Skip to main content
improved code formatting
Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

You could just add something like:

    // Remove 1 point if their post get removed
function deletePointFromUser($post_id) {
  $post = get_post($post_id);

  if( $post->post_type != 'post' ) return;//added code

  $authorid = $post->post_author;
  $currentQPointNumber = get_user_meta($authorid, 'points', true);
  // Delete 1 to the current Point Score
  update_user_meta($authorid, 'points', $currentQPointNumber-1); 
 }
add_action('wp_trash_post', 'deletePointFromUser');

Then your point subtraction will only occur if the $post$post is a post.

You could just add something like:

    // Remove 1 point if their post get removed
function deletePointFromUser($post_id) {
$post = get_post($post_id);

if( $post->post_type != 'post' ) return;//added code

$authorid = $post->post_author;
$currentQPointNumber = get_user_meta($authorid, 'points', true);
// Delete 1 to the current Point Score
update_user_meta($authorid, 'points', $currentQPointNumber-1); 
 }
add_action('wp_trash_post', 'deletePointFromUser');

Then your point subtraction will only occur if the $post is a post.

You could just add something like:

// Remove 1 point if their post get removed
function deletePointFromUser($post_id) {
  $post = get_post($post_id);

  if( $post->post_type != 'post' ) return;//added code

  $authorid = $post->post_author;
  $currentQPointNumber = get_user_meta($authorid, 'points', true);
  // Delete 1 to the current Point Score
  update_user_meta($authorid, 'points', $currentQPointNumber-1); 
}
add_action('wp_trash_post', 'deletePointFromUser');

Then your point subtraction will only occur if the $post is a post.

Source Link
Douglas.Sesar
  • 1.4k
  • 1
  • 9
  • 13

You could just add something like:

    // Remove 1 point if their post get removed
function deletePointFromUser($post_id) {
$post = get_post($post_id);

if( $post->post_type != 'post' ) return;//added code

$authorid = $post->post_author;
$currentQPointNumber = get_user_meta($authorid, 'points', true);
// Delete 1 to the current Point Score
update_user_meta($authorid, 'points', $currentQPointNumber-1); 
 }
add_action('wp_trash_post', 'deletePointFromUser');

Then your point subtraction will only occur if the $post is a post.