Dave, your code seems good except a couple things in it, so please try it:
function exclude_featured_post( $query ) {
if ( is_front_page() && $query->is_main_query() ) {
$meta_query = $query->get('meta_query') ? $query->get('meta_query') : array();
// append yours
$meta_query[] = array(
'key' => 'featured_post', // please make sure that key is correct
'value' => '1',
'compare' => '!=' // you can also try 'NOT EXISTS' comparison
);
$query->set('meta_query', $meta_query);
}
}
add_action( 'pre_get_posts', 'exclude_featured_post' );
If the above code doesn’t work for you, please follow these steps:
-
Make sure that it is running for homepage main query – just try to echo something inside it or so – this step help you to understand if the condition on line 2 is correct.
-
Try to play with more simple params like
orderby
etc. Check if it works. -
Test this code for posts which doesn’t have another
meta_query
parameters -
Try to use
meta_key
,meta_value
andmeta_compare
params instead of meta_query, example you can find here https://rudrastyh.com/wordpress/meta_query.html -
And make sure that key
feature_post
is correct, it hard to believe but among my students it is the most common mistake.