Exclude posts from main loop based on meta value

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:

  1. 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.

  2. Try to play with more simple params like orderby etc. Check if it works.

  3. Test this code for posts which doesn’t have another meta_query parameters

  4. Try to use meta_key, meta_value and meta_compare params instead of meta_query, example you can find here https://rudrastyh.com/wordpress/meta_query.html

  5. And make sure that key feature_post is correct, it hard to believe but among my students it is the most common mistake.