Created
July 23, 2012 14:50
-
-
Save norcross/3164028 to your computer and use it in GitHub Desktop.
filter search result to hide old posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rkv_search_filter( $where = '' ) { | |
// don't touch anything outside of a search query | |
if(is_admin() || !is_search() ) | |
return $where; | |
// Hide posts older than 2 years old | |
if ( is_search() ){ | |
$where .= "AND post_type = 'post' AND post_date >= '" . date('Y-m-d', strtotime('-730 days')) . "'"; | |
return $where; | |
} | |
} | |
add_filter('posts_where', 'rkv_search_filter'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Take a look at the code in this plugin: https://github.com/norcross/gist-sidebar-widget I use transients there to store the API call so I don't hit the limits.