That is correct. Relevanssi disables the default search query with the WHERE 1=2
, because there’s no point in running a query where you the results are not used.
If you want to run non-Relevanssi search queries for some reason, you can disable Relevanssi with
remove_filter( 'posts_request', 'relevanssi_prevent_default_request' );
remove_filter( 'the_posts', 'relevanssi_query', 99 );
Thread Starter
Shamalli
(@mihail-chepovskiy)
Thank you, it works!
After these filters can I use relevanssi_do_query($query); to do Relevanssi’s job?
Like this
remove_filter( 'posts_request', 'relevanssi_prevent_default_request' );
remove_filter( 'the_posts', 'relevanssi_query', 99 );
$args = array(
's' => 'test',
);
$query = new WP_Query($args);
relevanssi_do_query($query);
Thread Starter
Shamalli
(@mihail-chepovskiy)
I mean, I am trying to use Relevanssi’s job in my custom WP_Query objects, is it possible?
Yes, you can use relevanssi_do_query()
at that point. But if you’re using relevanssi_do_query()
like that, you don’t need to disable Relevanssi. Instead, I would recommend you do it like this:
$args = array(
's' => 'test',
);
$query = new WP_Query();
$query->parse_query( $args );
relevanssi_do_query($query);
This way the default query won’t be run in the first place and you avoid the useless query and instead just get the Relevanssi results.