How to make pages more relevant than posts (or custom post types)

[ad_1]

Relevanssi Premium has post type weights on the search settings page. Free version doesn’t, but you have other options.

If you want to ensure all pages come up first, you can sort the results by post type.

Here’s a filter function for increasing the weight of the pages:

add_filter( 'relevanssi_results', function( $postid_weight) {
    array_walk( $postid_weight, function( &$weight, $post_id ) {
        $post_type = relevanssi_get_post_type( $post_id );
        if ( 'page' === $post_type ) {
            $weight *= 100;
        }
    });
    return $postid_weight;
} );

Adding extra keywords helps, too. Relevanssi counts how many times each word appears in the post and uses that in calculations; you can add, for example, a custom field that has extra keywords to boost the pages.

Perfect thank you!

I will ask the customer if they want to buy premium. But this workaround works fine for the moment!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer