Skip to main contentSkip to footer

Hello, I’m using WooCommerce and Relevanssi and they work great.

My Site Search only searches Products, however I want to let certain posts appear in the search results.

Is there a way to allow certain posts to be in the results?

Yes. There are many ways to do this, and the best way depends on how many posts you want to include and how often you need to change the posts included.

I’d do this by enabling posts in the site search, but then disabling indexing for all posts except those you want to include with relevanssi_indexing_restriction. This is a great solution if you have a fairly small and stable number of posts you want to include.

add_filter( 'relevanssi_indexing_restriction', 'rlv_index_only_some_posts' );
function rlv_index_only_some_posts( $restriction ) {
  $posts_to_include       = implode( ',', array( 1, 2, 3 ) );
  $restriction['mysql']  .= " AND ( ( post.post_type = 'post' AND post.ID IN ( $posts_to_include ) ) OR post.post_type != 'post' ) ";
  $restriction['reason'] .= ' Unwanted post';
  return $restriction;
}

Add this to your site and list the posts you want to include in the $posts_to_include array (instead of 1, 2, 3). If you want this to target a post type other than post, adjust that in the post.post_type fifelds. Then rebuild the index, and only the posts you want to include will be indexed.

This question was originally asked on the WP support forums.

Your account

Not logged in. Log in to see your license details.

Search

Popular Resources

Search shortcode

Relevanssi adds a shortcode to help making links to search results. That way users can easily find more information about a given subject from your blog. The syntax is simple: John Doe This will make the text John Doe a link to search results for John Doe. In case you…

Why we don’t offer free trials

…wish. Why does Relevanssi Premium cost as much as it does? Selling Relevanssi Premium is our business and main source of income: it keeps us afloat. That’s simple and something most people will agree with. There are people who question selling software licenses or complain about the prices. You may……from a customer’s site. We could do that if the plugin required an activation code. Relevanssi Premium does use license keys. The keys only control access to upgrades and features that use our resources. Currently, that means the attachment content reading. This happens on our server and uses our resources,……that is to buy a license. If it doesn’t work for you, you can get a refund within 30 days without problems or too many questions (though we would really prefer that if you have problems getting Relevanssi to work, you’d at least give us a chance to fix them…

Related Posts:

Comment Section:

2 Comments. Leave new

  • Hi there!

    I would like to know if there is a way to give relevance to certain custom post. I mean, I have multiple post type on my website, however, I have one custom post named “programs” that it is the most importat, so what I want to do is, when a user search, por example, Executive Education, the first results should the custom post named “programs” and then the rest, por example the blog entries. Actually the searcher find all the results in all the post, so, if I have the word “Executive Education” wrote in a entry, the searcher gonna show me that entry, what is fine, but what I would like to see in first place is “Executive Education” as a program that it is the main tittle of that post and not inside of the post content.

    This is possible?

    Reply
    • This is easiest to do with Relevanssi Premium. Relevanssi Premium has a pinning feature, so you could go to the “Programs” post and pin it for the “Executive Education” search. Now when someone searches for “Executive Education”, that post comes up first.

      Relevanssi Premium also has an option to adjust post type weights from the settings so that you can increase the weight of all the posts in the “Programs” post type.

      If you don’t want to buy Premium, you can achieve all this with post type sorting and filtering, but it’s easiest with Premium.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed