• Resolved Rasso Hilber

    (@nonverbla)


    Hi there! I have a use case where I would like to be able to include/exclude a certain custom field’s value based on different search context.

    For example, imagine I have a checkbox that says “search custom field ‘team'” and if that checkbox is ticket, search results would only contain posts where the team custom field contains the search term(s). If unticked, these posts would not show up at all, except if the search term also appears in other custom fields. Hope this makes sense 🙂

    Do you have any recommendations on how to implement something like this with Relevanssi? My first idea was to exclude the custom field from the relevanssi index and then combine the search query with a custom meta_query

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

    (@msaari)

    With Relevanssi Premium, you can use the relevanssi_match hook (see this documentation) for shutting down specific custom fields in the search based on a query parameter.

    With the free version, the same method cannot be used, as the customfield_detail field that lists which custom fields match the search term is a Premium feature.

    With the free version, you can do something similar and check the desired custom field value with get_post_meta() within the relevanssi_match function. That takes some care, as you can end up doing a ton of extra database queries (you want to do a single database query to fetch the custom field value for all posts at once and then use that data).

    Or, you can do meta_query, that’s a fine approach, too.

    Thread Starter Rasso Hilber

    (@nonverbla)

    Niiice! I have Relevanssi Premium, so I can make use of the customfield_detail detection. Will try this out. Thanks for your quick response. Stellar support as always! 🌟

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Include/Exclude custom field value based on context’ is closed to new replies.