Forums

[resolved] [Plugin: JSON API & Relevanssi] Relevanssi not able to return json results? (3 posts)

  1. strop
    Member
    Posted 1 year ago #

    Good day everyone.

    I'm currently working on a rather large site for a client and the need for searching taxonomies and better search results has become apparent.

    I'm currently using the JSON API for an ajax search and that is working great. I enabled the Relevanssi plugin and the search results are, once again, working great. However, as soon as I try to get the results in JSON format with &json=1, it only returns the default search results.

    My guess is that the hooks that relevanssi use to change the default search behaviour isn't that compatible with the hooks JSON api uses.

    Any ideas and/or suggestions on how to resolve this?

    Thanks in advance.

  2. msaari
    Member
    Posted 1 year ago #

    I don't know how JSON API works. I've never heard of the plugin, so it's no surprise Relevanssi doesn't quite cooperate.

    Looking at it, I suppose the API gets the search results in a way that doesn't trigger Relevanssi. Relevanssi uses the_posts hook and checks for is_search(). If either of these doesn't happen, Relevanssi won't activate.

    Ok, looks like I figured it out... in /singletons/introspector.php, the set_posts_query() function fetches the search results (and other post arrays) with query_posts(). That would need to be changed... See this pastebin.

  3. strop
    Member
    Posted 1 year ago #

    That worked out perfectly! Thank you so so much for both the quick response and the great solution!

Topic Closed

This topic has been closed to new replies.

About this Topic