• Resolved Shamalli

    (@mihail-chepovskiy)


    Hello,

    $args  = array(
    	's' => 'test',
    );
    $query = new WP_Query($args);
    var_dump($query->request);

    This code gives me “SELECT * FROM wp_posts WHERE 1=2” when Relevanssi enabled. Disabled Relevanssi gives me correct search results sql.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mikko Saari

    (@msaari)

    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?

    Plugin Author Mikko Saari

    (@msaari)

    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.

    Thread Starter Shamalli

    (@mihail-chepovskiy)

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Broken search when Relevanssi enabled’ is closed to new replies.