• Resolved joshuaiz

    (@joshuaiz)


    Hello,

    I’ve tried to search for this in the Knowledge Base and on the forums but couldn’t find anything.

    Is there a way to increase the weight for Pages over Posts? Or to show Pages first in the results and then Posts?

    For the particular site I’m working on, most of the important content is on Pages however we still have a lot of Posts. The ability to prioritize Pages would be ideal.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter joshuaiz

    (@joshuaiz)

    Ahhh found it using the relevanssi_hits_filter here:

    
    add_filter('relevanssi_hits_filter', 'pages_first');
    function pages_first($hits) {
        $types = array();
     
        $types['page'] = array();
        $types['post'] = array();
     
        // Split the post types in array $types
        if (!empty($hits)) {
            foreach ($hits[0] as $hit) {
                array_push($types[$hit->post_type], $hit);
            }
        }
     
        // Merge back to $hits in the desired order
        $hits[0] = array_merge( $types['page'], $types['post'] );
        return $hits;
    }
    
    Plugin Author Mikko Saari

    (@msaari)

    Yes, that’s the way to do it for sure. Relevanssi Premium also has a simple setting for weighting post types. With free version, that code is the best way to do this, and makes sure pages are before posts.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Weigh Pages higher than Posts’ is closed to new replies.