Automattic\WooCommerce\Blocks\BlockTypes\ProductCollection
QueryBuilder::get_featured_query()
Generates a tax query to filter products based on their "featured" status. If the $featured parameter is true, the function will return a tax query that filters products to only those marked as featured. If $featured is false, an empty array is returned, meaning no filtering will be applied.
Method of the class: QueryBuilder{}
No Hooks.
Return
Array
. A tax query for fetching featured products if $featured is true; otherwise, an empty array.
Usage
// private - for code of main (parent) class only $result = $this->get_featured_query( $featured );
- $featured(true|false) (required)
- A flag indicating whether to filter products based on featured status.
QueryBuilder::get_featured_query() QueryBuilder::get featured query code WC 9.6.1
private function get_featured_query( $featured ) { if ( true !== $featured && 'true' !== $featured ) { return array(); } return array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query 'tax_query' => array( array( 'taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured', 'operator' => 'IN', ), ), ); }