Support » Plugin: Relevanssi - A Better Search » How to make it work with WP_Query?

  • Hello,

    Thank you for this plugin.
    Promised features look really good, however, I’m building a custom WordPress template and I need help integrating it with WP_Query, mine looks like this:

    $args = array(
    's'= $search,
    'paged'=$current_page,
    'offset'=$offset,
    'posts_per_page'=$posts_per_page,
    'post_type'='events',
    'order'='DESC',
    );

    Is there a param to add support to it?

    PS: Installing it broke my search, it’s always returning empty WP_Query object. Any thoughts?

    Thanks again,
    Cheers!

    • This topic was modified 5 years, 9 months ago by Maroun Melhem.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Do it like this:

    $args = array(...);
    $query = new WP_Query();
    $query->parse_query( $args );
    relevanssi_do_query( $args );

    Now your $query->posts has the Relevanssi-generated results.

    As for the broken search, that would depend on your templates and the parameters you’re feeding to the search.

    Thread Starter Maroun Melhem

    (@marounmelhem)

    Hello Mikko,

    Thank you for your reply,

    I’ve tested the above code and it’s still not working, I’m creating the search query on WordPress as an API (while loading WordPress inside it of course).

    All WordPress functions work flawlessly, you think this might be the issue?

    Let me know,

    Plugin Author Mikko Saari

    (@msaari)

    Have you enabled Relevanssi on WP admin? If it’s not a front-end search, it will look like an admin search to Relevanssi, and if Relevanssi is disabled on admin searches, it will not work.

    But instead of guessing, I would suggest you dive into Relevanssi source code and debug. Check what happens inside relevanssi_do_query() in your case, that’s the best way to figure out why it’s not working. Most of the search process can be found in lib/search.php in the Relevanssi folder.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to make it work with WP_Query?’ is closed to new replies.