Posted on

Indexing custom post statuses

If you’re using custom post statuses, Relevanssi requires some tinkering. By default, Relevanssi only handles posts that are of status publish, pending, draft or private.

Relevanssi has a filter that lets you add more statuses to the list of acceptable statuses for Relevanssi. Add this to your site:

function rlv_add_status( $status_array ) {
    $status_array[] = 'new_status';
    return $status_array;
}
add_filter( 'relevanssi_valid_status', 'rlv_add_status' );
add_filter( 'relevanssi_valid_admin_status', 'rlv_add_status' );

This function, added to the two filters, makes Relevanssi accept the status new_status.

You also need to let search know that it’s ok to show these posts to users, using the relevanssi_post_ok filter hook:

add_filter( 'relevanssi_post_ok', 'rlv_allow_custom_status', 11, 2 );
function rlv_allow_custom_status( $post_ok, $post_id ) {
    $status = relevanssi_get_post_status( $post_id );
    if ( 'new_status' === $status ) {
      $post_ok = true;
    }
    return $post_ok;
}

With these functions, Relevanssi will now work with the status new_status.

4 comments Indexing custom post statuses

    1. Add this to your theme functions.php:

      add_filter( 'relevanssi_valid_status', 'rlv_only_publish' );
      function rlv_only_publish( $status ) {
          return array( 'publish' );
      }
  1. What if the custom post status is also in a custom post type? Does an “If (” condition needed to be added for post type?

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 *