• Resolved Jellico

    (@catsfoto1se)


    Hi!

    I’m trying to build a searchable database for a hospital library, and I’ve encountered an issue with how categories and tags are being applied in the search results.

    Here’s the situation:

    • When I conduct a search using the URL structure ?s=test&cat=6,46&tag=fakta, I am expecting the results to only show posts that match either category 6 or 46, while also having the “fakta” tag.
    • However, I am receiving posts that do not have the specified tag but do match one of the categories.

    I would like to ensure that when a search is performed:

    1. Categories work as an “OR” condition, meaning the post can belong to any of the selected categories.
    2. Tags work as an “AND” condition, meaning the post must match at least one of the selected categories and the selected tag(s).

    If this behavior isn’t default, could you guide me on how to configure Relevanssi to achieve this filtering logic?

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

    (@msaari)

    This isn’t a Relevanssi issue, this is a WordPress issue. Relevanssi just follows the taxonomy parameters it gets, and this is how the logic in taxonomy parameters works in WordPress by default. You can’t control this from the query parameters directly, it’ll just follow the default logic.

    However, WordPress has a better method for specifying taxonomy parameters: create a tax_query from the parameters. Then you can define that the category and tag parameters have an AND logic between them; now it’s an OR logic.

    Tax query documentation can be found in WP_Query documentation in the WP Codex.

    Thread Starter Jellico

    (@catsfoto1se)

    Hi!

    thnx for the answer, I gave it to my AI, and surprisingly it did solve it.. thnx

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