Automattic\WooCommerce\Admin\API
Products::get_items
Get a collection of posts and add the post title filter option to WP_Query.
Method of the class: Products{}
No Hooks.
Returns
WP_Error|WP_REST_Response.
Usage
$Products = new Products(); $Products->get_items( $request );
- $request(WP_REST_Request) (required)
- Full details about the request.
Products::get_items() Products::get items code WC 10.8.1
public function get_items( $request ) {
add_filter( 'posts_fields', array( __CLASS__, 'add_wp_query_fields' ), 10, 2 );
add_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10, 2 );
add_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10, 2 );
add_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10, 2 );
$response = parent::get_items( $request );
remove_filter( 'posts_fields', array( __CLASS__, 'add_wp_query_fields' ), 10 );
remove_filter( 'posts_where', array( __CLASS__, 'add_wp_query_filter' ), 10 );
remove_filter( 'posts_join', array( __CLASS__, 'add_wp_query_join' ), 10 );
remove_filter( 'posts_groupby', array( __CLASS__, 'add_wp_query_group_by' ), 10 );
/**
* The low stock query caused performance issues in WooCommerce 5.5.1
* due to a) being slow, and b) multiple requests being made to this endpoint
* from WC Admin.
*
* This is a temporary measure to trigger the user’s browser to cache the
* endpoint response for 1 minute, limiting the amount of requests overall.
*
* https://github.com/woocommerce/woocommerce-admin/issues/7358
*/
if ( $this->is_low_in_stock_request( $request ) ) {
$response->header( 'Cache-Control', 'max-age=300' );
}
return $response;
}