Title: Exclude Posts Newer Than&#8230;
Last modified: September 11, 2016

---

# Exclude Posts Newer Than…

 *  [mrlambdas](https://wordpress.org/support/users/mrlambdas/)
 * (@mrlambdas)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/exclude-posts-newer-than-2/)
 * Is there a way to exclude posts newer than a a given date as in the published
   age of posts? I believe this is where it is being set in display-posts.php,
 *     ```
       // How old should the posts be?
       	if ( $args['how_old'] ) {
       		$where .= $wpdb->prepare( " AND $wpdb->posts.post_date > '%s' ", gmdate( 'Y-m-d H:m:s', $current_time - ( $args['how_old'] * DAY_IN_SECONDS ) ) );
       	}
       ```
   
 * To which I’ve tried adding the line
    `$where .= $wpdb->prepare( " AND $wpdb->
   posts.post_date > '%s' ", gmdate( 'Y-m-d H:m:s', $current_time - ( 2 * DAY_IN_SECONDS)));`
   unsuccessfully. Is there already a way that I have overlooked in the settings?

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

 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/exclude-posts-newer-than-2/#post-8171407)
 * Can you try to use `<` instead of the `>` for comparing the post date. Note that
   this won’t stay until the next update.
 * A better option would be to have a function filter tptn_posts_where and add the
   line you have above in the function.
 * Examples of these filter functions are : [https://github.com/WebberZone/top-10/blob/v2.3.0/includes/modules/taxonomies.php](https://github.com/WebberZone/top-10/blob/v2.3.0/includes/modules/taxonomies.php)
 *  Thread Starter [mrlambdas](https://wordpress.org/support/users/mrlambdas/)
 * (@mrlambdas)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/exclude-posts-newer-than-2/#post-8171585)
 * Awesome, so the %s is like the ? in mysqli and prepare is like bind_param. Thanks
   for the help! If I understand correctly this should be a function in our functions.
   php as to not overwrite during updates?
 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/exclude-posts-newer-than-2/#post-8194859)
 * Yes that is correct. You need to put the functions.php as the next update will
   overwrite all of these.
 * The %s and prepare are inbuilt WP functions for santising the output
 * [https://developer.wordpress.org/reference/classes/wpdb/prepare/](https://developer.wordpress.org/reference/classes/wpdb/prepare/)

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

The topic ‘Exclude Posts Newer Than…’ is closed to new replies.

 * ![](https://ps.w.org/top-10/assets/icon-256x256.png?rev=2986432)
 * [WebberZone Top 10 — Popular Posts](https://wordpress.org/plugins/top-10/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/top-10/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/top-10/)
 * [Active Topics](https://wordpress.org/support/plugin/top-10/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/top-10/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/top-10/reviews/)

## Tags

 * [exclude](https://wordpress.org/support/topic-tag/exclude/)
 * [newest](https://wordpress.org/support/topic-tag/newest/)

 * 3 replies
 * 2 participants
 * Last reply from: [Ajay](https://wordpress.org/support/users/ajay/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/exclude-posts-newer-than-2/#post-8194859)
 * Status: not resolved