I managed to get it to work with the listing grid with short function that modifies the WP query.
For whoever is interested:
- Modify the query when the URL includes ymm_search=1
- Check if query is for products -> gets matching product id’s.
- Replaces the result to only include these product IDs.
add_action('pre_get_posts', 'custom_ymm_query_modification', 9999);
function custom_ymm_query_modification($query) {
if (is_admin() || empty($_GET['ymm_search']) || '1' !== $_GET['ymm_search']) {
return;
}
$post_type = $query->get('post_type');
if ((is_array($post_type) && !in_array('product', $post_type, true)) || 'product' !== $post_type) {
return;
}
if (class_exists('Pektsekye_Ymm_Controller_Product')) {
$controller = new Pektsekye_Ymm_Controller_Product();
if (method_exists($controller, 'getFoundProductIds')) {
$found_ids = $controller->getFoundProductIds();
if (is_array($found_ids) && !empty($found_ids)) {
$query->set('post__in', $found_ids);
$query->set('orderby', 'post__in');
} else {
$query->set('post__in', array(0));
}
$query->set('s', false);
}
}
}
-
This reply was modified 1 month, 1 week ago by
yahavcaine.