Title: If Statement?
Last modified: August 19, 2016

---

# If Statement?

 *  [Nith](https://wordpress.org/support/users/nith/)
 * (@nith)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/if-statement-2/)
 * Hello,
 * I’m trying to create an if statement to check wether a post has been posted in
   a specific month/year. I’m not that proficient with inbuilt functions :/
 *     ```
       if(in_month(get_the_ID(), $filter['month']) && in_year(get_the_ID(), $filter['year'])) {
            // My code here
       }
       ```
   
 * Obviously, in_month and in_year are fictional wordpress functions, but you get
   the idea of what I’m trying to achieve.
 * Thanks.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/if-statement-2/#post-1550411)
 *     ```
       if( get_the_time('n') == $month && get_the_time('Y') == $year ) {
       // your code here
       }
       ```
   
 * define the variables $month and $year before that snippet.
 * [http://uk.php.net/manual/en/function.date.php](http://uk.php.net/manual/en/function.date.php)
   
   [http://codex.wordpress.org/Function_Reference/get_the_time](http://codex.wordpress.org/Function_Reference/get_the_time)
 *  Thread Starter [Nith](https://wordpress.org/support/users/nith/)
 * (@nith)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/if-statement-2/#post-1550433)
 * Ah, get_the_time() is the function I was looking for 🙂
 *     ```
       if(get_the_time('F') == $filter['month'] && get_the_time('Y') == $filter['year']) {
       	// My code here
       }
       ```
   
 * Worked great.
 * Ty.

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

The topic ‘If Statement?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Nith](https://wordpress.org/support/users/nith/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/if-statement-2/#post-1550433)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
