• I’ve set up some Synonyms for one of my search terms e.g.

    car crash = personal injury
    construction accidents = personal injury
    dog bites = personal injury

    My results are being pulled through correctly, but I need to also output the current synonym that’s been searched.

    For example: If I search for Dog Bites, my search results need to be pulled in with a title of ‘Personal Injury’.

    How can I output the current synonym?

    https://ww.wp.xz.cn/plugins/relevanssi/

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

    (@msaari)

    The synonym data is stored in the option relevanssi_synonyms, so $synonym_data = get_option('relevanssi_synonyms'); will fetch you the list of synonyms. It’s stored with the pairs separated by semicolons, thus $pairs = explode(";", $synonym_data);. Now $pairs contains all the synonym pairs. You can go through the list and figure out what the current search query (get_search_query()) matches.

    Or, you can use:

    $q = relevanssi_add_synonyms(trim(stripslashes(mb_strtolower(get_search_query())));`

    Now $q will have the query and the synonyms (eg. “dog bites personal injury”), then just subtract the query from it.

    There’s no direct method of getting the synonyms matching the current query.

Viewing 1 replies (of 1 total)

The topic ‘Find the current synonym’ is closed to new replies.