Posted on

Excluding old content from the search

Is there a way to exclude anything before 2016 from search results?

Yes. There are two approaches to this. If you never want to see anything old in the results, it’s best to filter in indexing with relevanssi_indexing_restriction. Add this to your site:

PHP

Note that the restriction explains which posts are included in the index, so that’s why the year is >= 2016 and not < 2016.

To deindex posts from the news post type that are older than one year, you can use:

PHP

If, on the other hand, you only want to apply this filter in searching, you can use the WP_Query date parameters like this:

PHP

Leave a Reply

Are you a Relevanssi Premium customer looking for support? Please use the Premium support form.

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