• Hi! I have a custom template with a search.php where it shows the search for three Custom Post Types (publication, project and news-post).

    Previously I had a code that worked great, it displayed the posts and used various filters to narrow down the results. I had a custom query with WP_Query to work with the filters.

    Now I have installed the Relevanssi plugin, which requires the use of the main WordPress query instead of a custom one (as I understand it). To maintain the filters, I added this function in functions.php. The problem is that the filter by author no longer works. When displaying the entries and filtering by author no results appear, but with the custom query it worked. What am I doing wrong?

    In the image I show the codes with comments for better understanding. The only filter that does not work is the author filter, the rest (that I did not add to the image) work fine.

    • This topic was modified 2 weeks, 5 days ago by Fai2115.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Relevanssi doesn’t require using the main query. Using the main query is a good idea for performance reasons because otherwise you’ll end wasting the main query. It’s not mandatory, though. The easiest way to deal with it is to set the relevanssi query parameter to true: add $args['relevanssi'] = true; before you run the WP_Query. Does that fix this?

    Thread Starter Fai2115

    (@fai2115)

    Great, thank you very much!! Adding $args['relevanssi'] = true; before running WP_Query made it work.

    Now another question. I have 3 posts that have an ‘author’ assigned to them (via a post object field), however when searching for that author it shows 2 posts instead of 3. Author is a custom post type. In the Relevanssi configuration I indexed all posts and both the ‘author’ CPT and the custom field (post object) are marked to be indexed by the plugin. I hope I explained myself well

    Plugin Author Mikko Saari

    (@msaari)

    When Relevanssi indexes the post object field, it doesn’t see the post object; it sees the post ID. You need to use the post ID to fetch the contents from the related post so that Relevanssi can index everything you want from the post. See https://www.relevanssi.com/knowledge-base/indexing-acf-relationship-content/.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.