WC_Product_Data_Store_CPT::get_featured_product_ids()
Returns a list of product IDs ( id as key => parent as value) that are featured. Uses get_posts instead of wc_get_products since we want some extra meta queries and ALL products (posts_per_page = -1).
Description Description
Return Return
(array)
Source Source
File: includes/data-stores/class-wc-product-data-store-cpt.php
public function get_featured_product_ids() {
$product_visibility_term_ids = wc_get_product_visibility_term_ids();
return get_posts(
array(
'post_type' => array( 'product', 'product_variation' ),
'posts_per_page' => -1,
'post_status' => 'publish',
'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query
'relation' => 'AND',
array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => array( $product_visibility_term_ids['featured'] ),
),
array(
'taxonomy' => 'product_visibility',
'field' => 'term_taxonomy_id',
'terms' => array( $product_visibility_term_ids['exclude-from-catalog'] ),
'operator' => 'NOT IN',
),
),
'fields' => 'id=>parent',
)
);
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |