Title: Conditional Statements in Functions.php
Last modified: August 24, 2016

---

# Conditional Statements in Functions.php

 *  [Chris Whiteley](https://wordpress.org/support/users/thewhite/)
 * (@thewhite)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/conditional-statements-in-functionsphp/)
 * I have a snippet of code running to remove a post from a category after a specified
   length of time, however I would like to exclude an author from this function.
   I have tried a few things to accomplish this with no success. I am really unsure
   how to accomplish this.
 * Here is the code use to remove the post from a category:
 *     ```
       function auto_cat_remove() {
           global $post;
           wp_schedule_single_event( time() + 20, 'remove_news_cat_event', array( $post->ID ) );
       }
   
       function remove_news_cat_func( $post_id ) {
           global $wpdb;
           $category_id = 598;
           $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->term_relationships WHERE object_id = %d AND term_taxonomy_id = %d", $post_id, $category_id ) );
   
       }
   
       add_action( 'wp_insert_post', 'auto_cat_remove' );
       add_action( 'remove_news_cat_event', 'remove_news_cat_func' );
       ```
   

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * (@rossmitchell)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/conditional-statements-in-functionsphp/#post-5988881)
 * In your function ‘auto_cat_remove’ where you have $post available, test the author
   and only schedule the removal if the author is not the protected one.
 *  Thread Starter [Chris Whiteley](https://wordpress.org/support/users/thewhite/)
 * (@thewhite)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/conditional-statements-in-functionsphp/#post-5988969)
 * Thanks for responding!
    I’m not exactly sure I fully understood your suggestion.
   I tried to interpreting it as this:
 *     ```
       function auto_cat_remove() {
           global $post;
       	$authorID = get_the_author_meta('ID');
       		if(!$authorID = 21) {
           	wp_schedule_single_event( time() + 20, 'remove_news_cat_event', array( $post->ID ) );
       	}
       }
       ```
   
 * But it was not successful. The function still fires not matter what author created
   the post.
 *  [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * (@rossmitchell)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/conditional-statements-in-functionsphp/#post-5988982)
 * You were close.
    Try this: `if( $authorID != 21 )`
 * I am surprised you didn’t get an error message. Your expression would be evaluated
   as:
    `( ( ! $authorID ) = 21 )` Which would have the value of 21, which is TRUE
 * If This revision does not work, then display your $author_ID to make sure it 
   matches the post.
 *  Thread Starter [Chris Whiteley](https://wordpress.org/support/users/thewhite/)
 * (@thewhite)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/conditional-statements-in-functionsphp/#post-5989012)
 * I gave your suggestion a try, but the function still fires no matter what the
   author ID is. I’ve confirmed the correct ID.
 * Is this not working because I am running this in functions.php instead of a theme
   page?
 *  [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * (@rossmitchell)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/conditional-statements-in-functionsphp/#post-5989016)
 * Have you confirmed that the correct ID is fetched in the context of your function.
   
   You have $post as a global but are not using it. Is there another way to fetch
   the author ID from the $post ?

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Conditional Statements in Functions.php’ is closed to new replies.

## Tags

 * [author](https://wordpress.org/support/topic-tag/author/)
 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 5 replies
 * 2 participants
 * Last reply from: [RossMitchell](https://wordpress.org/support/users/rossmitchell/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/conditional-statements-in-functionsphp/#post-5989016)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
