I'm trying something but I have an issue with WP_Query.
I've an Hook on the_post in order to add some variation on the query.
add_filter('the_posts', 'query_variation');
function query_variation($posts, $query = false) {
if (is_search())
{
// Do stuff
}
}
It's working well when I'm searching on the site. But, I know creating an ajax search like that :
function ajax_search_123( ){
$search_keyword = esc_attr($_REQUEST['query']);
$args = array(
's' => $search_keyword),
'post_type' => 'product',
'posts_per_page' => 3,
);
$products_query = new WP_Query( $args );
// Do stuff with $product_query
}
But when I instanciate WP_Query with $args, is_search() doesn't return true so I'm entering on the if...
What Can I do ?
Thank you for your help
pre_get_posts
action.