wc_get_products( array $args )
Standard way of retrieving products based on certain parameters.
Description Description
This function should be used for product retrieval so that we have a data agnostic way to get a list of products.
Args and usage: https://github.com/woocommerce/woocommerce/wiki/wc_get_products-and-WC_Product_Query
Parameters Parameters
- $args
-
(Required) Array of args (above).
Return Return
(array|stdClass) Number of pages and an array of product objects if paginate is true, or just an array of values.
Source Source
File: includes/wc-product-functions.php
function wc_get_products( $args ) {
// Handle some BW compatibility arg names where wp_query args differ in naming.
$map_legacy = array(
'numberposts' => 'limit',
'post_status' => 'status',
'post_parent' => 'parent',
'posts_per_page' => 'limit',
'paged' => 'page',
);
foreach ( $map_legacy as $from => $to ) {
if ( isset( $args[ $from ] ) ) {
$args[ $to ] = $args[ $from ];
}
}
$query = new WC_Product_Query( $args );
return $query->get_products();
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |