Posted on

Indexing trashed posts

By default, Relevanssi does not index trashed posts. If you want to enable searching for trashed posts in the WordPress admin, it’s simple: all you need to do is to give Relevanssi permission to a) include posts with the trash status in the index and b) allow the trash status posts to show up in the admin search.

Doing this requires a small bit of code:

add_filter( 'relevanssi_valid_status', 'rlv_include_trash' );
add_filter( 'relevanssi_valid_admin_status', 'rlv_include_trash' );
function rlv_include_trash( $statuses ) {
    $statuses[] = 'trash';
    return $statuses;
}

Add this code to your site and then rebuild the index to include trashed posts in the admin search results.

This function does both jobs at once: it adds trash to the list of allowed statuses for indexed posts (the relevanssi_valid_status filter hook) and to the list of allowed statuses in admin searches (the relevanssi_valid_admin_status filter hook).

6 comments Indexing trashed posts

  1. Thanks for sharing. Are author roles able to search for posts in the trash? I know that they can create and edit their own posts. How about posts they deleted?

  2. This is helpful. When I add custom post statuses like in your code and re-index, I see the index change size to include these posts. However, when I use admin search I don’t see the posts showing up in results. Any ideas?

    1. Matthew, when you say “admin search”, do you mean the general WP backend search or the Relevanssi admin search? If you’re talking about the general WP backend search, it’s quite possible it won’t work there. The posts should appear in the Relevanssi admin search, though (Dashboard > Admin search).

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 *