Automattic\WooCommerce\Internal\Admin\Reports
ProductSearchQuery::get_ids
Returns the product IDs the given search terms resolve to.
For callers that need the matches themselves rather than a statement to compose with. An empty list means the terms matched nothing, which is not the same as null, meaning there was nothing to search for.
Method of the class: ProductSearchQuery{}
No Hooks.
Returns
int[]|null. Matching product IDs, or null when there is nothing to search for.
Usage
$result = ProductSearchQuery::get_ids( $terms, $restrict_to_ids );
- $terms(string|string[]) (required)
- Search terms. A product matches if it matches any term.
- $restrict_to_ids(int[])
- Product IDs to intersect the results with.
Default:array()
Changelog
| Since 11.2.0 | Introduced. |
ProductSearchQuery::get_ids() ProductSearchQuery::get ids code WC 11.3.0
public static function get_ids( $terms, $restrict_to_ids = array() ) {
global $wpdb;
$subquery = self::get_ids_subquery( $terms, $restrict_to_ids );
if ( '' === $subquery ) {
return null;
}
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- $subquery is built from prepared fragments; the containing report is what caches.
return array_map( 'intval', $wpdb->get_col( $subquery ) );
}