Skip to main contentSkip to footer

Sometimes it can happen the search results include posts from a post type that has been excluded from the index. When that happens, here are things you can check.

Are you using Relevanssi?

It’s possible your search results are not coming from Relevanssi. The quickest way to check is to use the Relevanssi admin search (Dashboard > Admin search). If you use the admin search and you’re still getting posts from the wrong post type, you can move on to the next step.

If the admin search gets you the correct results but your theme front end search doesn’t, your theme search is not using Relevanssi for some reason.

Common causes for indexing the wrong post types

The most common reason for index including the wrong post type is a shortcode or some other feature that displays posts and confuses Relevanssi.

In the case that prompted this post, the search was showing posts from the publication post type, even though that post type was excluded from the index. The reason was a shortcode, publication_archive, that was used on a page to display an archive of publications.

The shortcode function fetched the posts with WP_Queryand changed the global $post object. That confused Relevanssi and when Relevanssi indexed the page, the post changed in the middle and the wrong post ended up in the index.

Something like this is the most common cause for the wrong post type ending up in the index.

Fixing the problem

In this case the solution was easy: just add the shortcode to the list of disabled shortcodes. Problem solved! This is easy to do in Relevanssi Premium where the list of disabled shortcodes is a simple setting field on the indexing settings page. With the free version, you can adjust this with the relevanssi_disabled_shortcodes filter hook.

If you want to index the shortcode contents, the solution is to modify the code so that it doesn’t touch the global $post object. That is generally the best way to work in any case. So, instead of using WP_Query, use get_posts() and instead of the_post(), just use a local object.

Your account

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

Search

Popular Resources

WP Download Manager

…these issues. When you upload the files to the Relevanssi attachment reading server, Relevanssi uses the get_attached_file() function to get the file name, but that does not work with WP Download Manager. Thus we need to use the relevanssi_get_attached_file filter hook to provide the file name and path for Relevanssi….…add-on adds an advanced search with the [wpdb_archive_filter] shortcode. That search does not use Relevanssi by default, but it can be modified to make use of Relevanssi with this little function you can add to your site: add_filter( ‘wpdm_packages_query_params’, ‘rlv_use_relevanssi’ ); function rlv_use_relevanssi( $params ) { if ( isset( $params[‘s’]…

Related Posts

caches the related posts for each post. The caches are stored in transients and are kept for two weeks before they expire. The cache includes the whole related posts element, so it’s lightning-fast to serve once it’s in the cache (especially with a setup that stores the transients in memory)….…two weeks. The related posts are loaded from the transient cache very quickly, without any performance loss on the site. And don’t worry about the long cache periods: if a post is removed, Relevanssi will purge all related caches so that it will disappear from related posts right away. Relevance:……related posts and also block posts. Control: Relevanssi makes sure the caches are flushed whenever necessary. You can also manually flush all related posts caches and there’s also a WP CLI command for regenerating all related posts. Setting up the related posts To get started, navigate to the Relevanssi settings…

Related Posts:

Comment Section:

3 Comments. Leave new

  • Hello,

    I am using a plugin “Get Paid” https://wordpress.org/plugins/invoicing/

    I need Relevanssi to include “wpi_invoice” at the search because it is excluded by default. It has “Yes” at “Excluded from search?” column. I need to get search results by searching within custom fields stored in every invoice.

    Thanks in advance

    Reply
    • Ashraf, you can’t change that value: it comes from the Get Paid plugin, and Relevanssi can’t do anything about it. Relevanssi doesn’t care about it, though; you can index the post type without problems. Uncheck the “Respect ‘exclude_from_search'” setting in the Relevanssi searching settings to make Relevanssi ignore that (but note that it will also open up the invoices to the front-end search – if you don’t want that, you need to control which post types are included in the search and which are not).

      Also, there may be some issues in searching post types that the plugin developers are not meant to be searched, it doesn’t always work smoothly if the other plugin makes it hard in some way.

      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