Automattic\WooCommerce\StoreApi\Utilities
ProductQuery::get_results
Get results of query.
Method of the class: ProductQuery{}
No Hooks.
Returns
Array.
Usage
$ProductQuery = new ProductQuery(); $ProductQuery->get_results( $request );
- $request(WP_REST_Request) (required)
- Request data.
ProductQuery::get_results() ProductQuery::get results code WC 10.8.1
public function get_results( $request ) {
$query_args = $this->prepare_objects_query( $request );
add_filter( 'posts_clauses', array( $this, 'add_query_clauses' ), 10, 2 );
$query = new \WP_Query();
$results = $query->query( $query_args );
$total_posts = $query->found_posts;
// Out-of-bounds, run the query again without LIMIT for total count.
if ( $total_posts < 1 && $query_args['paged'] > 1 ) {
unset( $query_args['paged'] );
$count_query = new \WP_Query();
$count_query->query( $query_args );
$total_posts = $count_query->found_posts;
}
remove_filter( 'posts_clauses', array( $this, 'add_query_clauses' ), 10 );
return array(
'results' => $results,
'total' => (int) $total_posts,
'pages' => $query->query_vars['posts_per_page'] > 0 ? (int) ceil( $total_posts / (int) $query->query_vars['posts_per_page'] ) : 1,
);
}