What hook/filter should I use for not display some post on my blog, (for example if the post written over the last year.) I want to use hook / filter and not code in the template so plugins or rss feed can't access it
You can use
pre_get_posts()
action, this hook is called after the query variable object is created, but before the actual query is run. So you have use it with different conditional.
Here is the sample code:
function wh_getThisYearPost($query)
{
if (($query->is_home()) //<-- for home page
|| $query->is_feed() //for feed
|| $query->is_search() // for search
)
{
//to get post from current year only.
$query->set('year', date('Y'));
}
}
add_action('pre_get_posts', 'wh_getThisYearPost');
Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
Please Note: The above code will not work on your custom WP_Query
you have manually add the Date Parameters in those query.
Hope this helps!