• bhylton

    (@bhylton)


    Is there a way to promote specific pages/posts based on certain keywords? For example, let’s say a user searched for ‘VPN’ and I wanted a specific document to always show up as the top result (similar to ‘Promotions’ on Google Custom Search). Thanks!

    (Checked Relevanssi settings but not seeing — apologies if overlooking)

    https://wordpress.org/plugins/relevanssi/

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

    (@msaari)

    Yes, it’s possible, but you have to write some code to do it, there’s no simple setting you can use.

    The best way to do it would be to use relevanssi_hits_filter filter hook. Something like this:

    add_filter('relevanssi_hits_filter', 'rlv_promote_posts', 10, 2);
    function rlv_promote_posts($hits, $query) {
        if (strpos($query, 'vpn') !== false) {
            $new_hits = array();
            $vpn_post = get_post(ID OF THE PROMOTED POST);
            $new_hits[] = $vpn_post;
            foreach ($hits[0] as $hit) {
                  if ($hit->ID != $vpn_post->ID) $new_hits[] = $hit;
            }
        }
        return array($new_hits);
    }

    This would put the post in $vpn_post on top of the results, if the search terms include word “vpn”. A bit clunky, but if you have only few posts you want to promote on few keywords, this should do the trick.

Viewing 1 replies (of 1 total)
  • The topic ‘Promoting Keywords’ is closed to new replies.