Support » Plugin: Relevanssi - A Better Search » Give certain pages a higher rank

  • Hello everyone,

    I have a page titled “Damian Lewis” and some posts titled “Damian Lewis wins Golden Globe” and “Damian Lewis stars in Homeland”.

    I would like to make sure that the “Damian Lewis” page always comes first in the searchresults. I can’t seem to get that to work, probable because the prashe “Damian Lewis” is used more in the posts content.

    Is there a workaround for this? Any help would be very much appreciated.

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


    Relevanssi Premium has a feature of adjusting weights by post type, in which case you could boost pages over posts. Otherwise a manual adjustment using either relevanssi_match or relevanssi_hits_filter filter hooks is the way to go.

    Thanks for your reply. I think I almost got it, but only pages are returned now. Can you see why this happens?

    add_filter('relevanssi_hits_filter', 'pages_first');
    function pages_first($hits) {
    	$pages = array();
    	$everything_else = array();
    	foreach($hits[0] as $hit){
    		$page = false;
    		if($hit->post_type == 'page'){
    			$page = true;
    	$page ? array_push($pages, $hit) : array_push($everything_else, $hit);
    	$hits[0] = array_merge($pages, $everything_else);
    	return $hits;
    Plugin Author Mikko Saari


    Now the loop goes through the hits, until it finds a page, then puts the page in the $pages array and returns that.

    Remove the break and put the array_push() stuff inside the foreach loop. Then $hits will contain all posts, pages first.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Give certain pages a higher rank’ is closed to new replies.