I am trying to remove the first three posts of a taxonomy from the main query. I’ve run a whole bunch of ideas and examples from around the internet but none seem to be achieving what I need or just throw up errors. I believe it needs to utilize pre get posts, which I’ve got the code below for as far as I’ve got. It’s not great but this has left me scratching my head and I can’t seem to find any solutions out there.
function excluded( $query ) {
if( $query->is_main_query() && ! is_admin() && $query->is_home() ) {
$query->set( 'tag__not_in', '8384' );
}
}
add_action( 'pre_get_posts', 'excluded' );
2
Answers
This was the code that ended up working perfectly for me. If there is a less expensive method or more efficient way, would certainly be open to it
You can try to use the below code, By this, you can exclude the posts by their ids.