Skip to main contentSkip to footer

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.

Your account

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

Search

Popular Resources

Showing only one recurring event

Some event calendar plugins do recurring events by creating many posts. That’s fine until those cloned posts fill up your search results. This function will only show one of each post with the same title and will take the one with the first date. The date is checked from _EventStartDate…$hits[0] as $hit ) { if ( ! isset( $posts_seen[ $hit->post_title ] ) ) { $ok_results[] = $hit; $date_by_title[ $hit->post_title ] = get_post_meta( $hit->ID, ‘_EventStartDate’, true ); $index_by_title[ $hit->post_title ] = $i; $posts_seen[ $hit->post_title ] = true; $i++; } else { if ( get_post_meta( $hit->ID, ‘_EventStartDate’, true ) < $date_by_title[……in the past. } $date_by_title[ $hit->post_title ] = get_post_meta( $hit->ID, ‘_EventStartDate’, true ); $ok_results[ $index_by_title[ $hit->post_title ] ] = $hit; } } } $hits[0] = $ok_results; return $hits; } Update 27.10.2017: Fixed the function to remove an “Undefined index” error and added a check for skipping events in the past….

Related Posts:

Comment Section:

4 Comments. Leave new

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