Recently, I needed to remove a specific post from a blog page. Here's how I did it.
[php]
add_filter( 'genesis_custom_loop_args', 'wps_exclude_post' );
function wps_exclude_post ( $args ) {
$args['post__not_in'] = array(6586); //Post ID
return $args;
}
[/php]
This code adds an argument to the WordPress query called 'post__not_in' which takes an array of post IDs. So, I could just create a laundry list of posts I don't want in; however, in my case I only needed to exclude one.
As always, this code goes in functions.php.
Joan BoludaJoan says
Hi Travis! I’m trying this code bit it doesn’t seem to work. Am I missing something? Is it still working? In fact, I cannot use the genesis_custom_loop_args filter at all, it has no effect on the loop.
Travis Smith says
Hello Joan,
This only works for pages using the Blog template,
page_blog.php
. Are you trying it on that page? Otherwise, you will need to use thepre_get_posts
hook and modify the query the standard WordPress way.