• Resolved kasiamcm

    (@kasiamcm)


    Hi!

    I am trying to ensure that a search returns matches to a specific custom field first (created by ACF), before it returns matches from any other content areas or other custom fields. Is this possible to do this with either the free version or premium? I have added the following filter which has improved the search results (custom field matches are showing higher), but I am still seeing matches in a particular custom field come after other matches.

    add_filter( 'relevanssi_match', 'rlv_customfield_boost' );
    function rlv_customfield_boost( $match ) {
        if ( $match->customfield > 0 ) {
            $match->weight *= 10;
        }
        return $match;
    }

    What do you recommend to ensure that matches to ONE custom field are at the top of the results?
    Thanks!
    Kasia

    • This topic was modified 1 year, 11 months ago by kasiamcm.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    You need Relevanssi Premium for that because Relevanssi Premium knows which custom fields match. You get that information in $match->customfield_detail. With the free version, you can check inside the $match->customfield > 0 conditional if the search term matches the specific custom field by fetching that field and comparing the search term ($match->term) to that, but it’s somewhat expensive.

    Thread Starter kasiamcm

    (@kasiamcm)

    Ok, thank you. I have sent the request to my client to purchase the premium version. Can you share a link to an example function that adds weight to a specific field using the info in customfield_detail? I don’t mind reading the docs but haven’t seen anything that explains how to access that info. Thank you!

    Thread Starter kasiamcm

    (@kasiamcm)

    Using premium plugin and found the doc here: https://www.relevanssi.com/knowledge-base/relevanssi-match/#customfield.
    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Search results that give most weight to one custom field’ is closed to new replies.