How to stop post edits being counted the same as creating a post
-
Hi
I have been able to get a step added that tracks when a user creates custom post types of ‘event’.
However during testing I have noticed that if I edit an event that this edit is getting counted, meaning I can get a badge if I create and event and then keep editing it several times. e.g. I want users to get a badge after creating 10 events, but the user creates one event and then edits it 9 times they will get the badge.
Many thanks for any help here!
I used the following adapted code that I found via another thread here, if that helps:
// Any time a post is published, we want to test to see if a user earns an achievement as a result of that post. // This will be calculated with 'win', 'loss', and 'mvp' content types. Wins, losses, total games, and mvps // all need to be calculated as individual stats so all of that is included here. function calc_game_triggers($post_id) { // First define the database as a global variable. global $wpdb; // Get some basic information about the post. $post = get_post($post_id); $post_type = $post->post_type; $post_author = $post->post_author; // Get some basic information about the post author. $user = get_userdata( $post_author ); $username = $user->user_login; // Code to run if the post is a 'event'; if ($post_type == 'event') { // We want to increment both wins and total games. $event_count = badgeos_update_user_trigger_count($post_author, 'create_event'); // Post log entries for both wins and total games. badgeos_post_log_entry( null, $author, null, sprintf('%1$s triggered %2$s (%3$dx)', $username, 'create_event', $event_count)); // Retrieve 'create_event' instances from the database. $triggered_event_achievements = $wpdb->get_results( $wpdb->prepare( " SELECT post_ID FROM $wpdb->postmeta WHERE meta_key = '_badgeos_trigger_type' AND meta_value = %s ", 'create_event' ) ); // Iterate through the 'win_game' instances and determine if any achievements need to be awarded. foreach ($triggered_event_achievements as $achievement) { badgeos_maybe_award_achievement_to_user( $achievement->post_ID, $post_author, 'create_event', get_current_blog_id(), '' ); } } } add_action('save_post', 'calc_game_triggers');
- The topic ‘How to stop post edits being counted the same as creating a post’ is closed to new replies.