WordPress Q&As Logo
WordPress Q&As Part of the Q&A Network
Q&A Logo

How can I create a custom query to show only featured posts?

Asked on Sep 07, 2025

Answer

To create a custom query that displays only featured posts in WordPress, you can utilize the WP_Query class with a meta query to filter posts marked as featured. This involves checking for a specific custom field or post meta key that indicates a post is featured.
<!-- BEGIN COPY / PASTE -->
    $args = array(
      'post_type' => 'post',
      'meta_query' => array(
        array(
          'key' => 'is_featured',
          'value' => '1',
          'compare' => '='
        )
      )
    );
    $featured_query = new WP_Query($args);
    if ($featured_query->have_posts()) {
      while ($featured_query->have_posts()) {
        $featured_query->the_post();
        // Display post content
      }
      wp_reset_postdata();
    }
    <!-- END COPY / PASTE -->
Additional Comment:
  • Ensure that your posts have a custom field named "is_featured" with a value of "1" for featured posts.
  • Use the WordPress Custom Fields feature or a plugin to add this meta key to your posts.
  • Remember to call wp_reset_postdata() after the loop to restore the original post data.
✅ Answered with WordPress best practices.

← Back to All Questions
The Q&A Network