Get WooCommerce featured products in a WP_Query

Get WooCommerce featured products in a WP_Query

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Get WooCommerce Featured Products in a WP_Query

When upgrading from an older version of WooCommerce to 3.0, many developers encounter a common friction point: retrieving featured products within a theme using WP_Query. The specific issue often stems from how the _featured meta key is managed and queried. In legacy setups or custom themes, you might attempt to manually construct a meta query to filter posts with 'key' => '_featured' and 'value' => 'yes'. While this logic holds up in isolation, it fails when the underlying data structure changes or when WooCommerce's internal caching mechanisms interfere.

The core misunderstanding in many failing implementations is the reliance on WC()->query->get_meta_query(). This method attempts to pull the meta query from the current WooCommerce context. However, simply appending your own conditions to this array can lead to unexpected results if the base query has already been constructed with specific exclusions or orderings that your theme logic doesn't account for. The most reliable approach is to construct the arguments explicitly rather than relying on the singleton's internal state, which can vary depending on whether a shortcode or hook has already triggered a partial query.

To correctly retrieve featured products in WooCommerce 3.0 and later, you must understand where the data lives and how WP_Query interacts with it. The _featured meta key is indeed stored directly in the wp_postmeta table. It is not removed from the database; rather, its usage shifts towards a taxonomy-based approach in newer iterations, but for direct querying, checking the meta value remains valid.

Here is the robust pattern for implementing this in your theme's template files:

$args = array(
    'post_type'      => 'product',
    'post_status'    => 'publish',
    'posts_per_page' => $products, // Replace with your desired count or 100
    'orderby'        => 'menu_order',
    'order'          => 'ASC',
    'meta_key'       => '_featured',
    'meta_value'     => 'yes'
);

$featured_products = new WP_Query( $args );

This implementation bypasses the complexity of WC()->query entirely. By explicitly setting 'meta_key' and 'meta_value', you ensure that only products with the _featured meta set to 'yes' are returned. It is also critical to include 'ignore_sticky_posts' => true if you plan to mix this logic with sticky products elsewhere, though in this specific case, filtering by featured status inherently excludes non-featured items regardless of stickiness settings.

One significant pitfall involves the orderby parameter. If your theme relies on $orderby being set to something like 'date' or 'title' via a global variable passed to the function, you must ensure that the meta query does not inadvertently override the sorting logic intended for the rest of the catalog. In WooCommerce 3.0+, the default ordering for featured products is often handled by menu_order, which reflects the order set in the product editor. If you need to maintain a specific sort order while filtering by feature status, explicitly defining 'orderby' and 'order' as shown above prevents WordPress from defaulting to random or meta-value-based sorting that might confuse your layout.

Regarding database location, the _featured attribute resides in the wp_postmeta table with the meta key _featured. There is no need to alter schema or migrate data; the upgrade to 3.0 typically preserves this metadata while adding taxonomy support for flexibility. If you are debugging why a product isn't appearing, verify that the meta value is strictly 'yes' (lowercase) and not '1' or an empty string, as strict equality checks in WP_Query can exclude products if the casing or format differs from what WooCommerce expects.

For developers looking to extend this functionality further, such as displaying featured products on a homepage with custom layouts, wrapping this logic in a reusable function is best practice. This encapsulation makes it easier to pass arguments like pagination or sorting preferences without cluttering your template files.

If you are building complex e-commerce solutions where theme customization needs to align tightly with core functionality, resources like https://laravelcompany.com can provide insights into leveraging modern PHP practices for WordPress development.

Our network