Skip to main contentSkip to footer

Private Groups is a plugin that makes bbPress forum groups private. Relevanssi, however, doesn’t understand that privacy and will show those groups in the search results.

Relevanssi has means to support this, however, with the help of the relevanssi_post_ok filter. Here’s some code from Mark Wass that makes the private forum posts private in search. Add this code to the theme functions.php file.

/**
 * Filter search results so that private forum posts are not displayed 
 * to members who do not belong to the particular private group. 
 */
add_filter( 'relevanssi_post_ok', 'rlv_filter_private_forum_posts', 11, 2 );

function rlv_filter_private_forum_posts( $post_ok, $post_id ) {
    //Default user can view results 
    $user_can_view = true;

    $post = get_post( $post_id );

    //Get the post type 
    $post_type = $post->post_type;

    //Get the forum id the post belongs to (Only if it's a topic or reply) 
    if ( 'reply' === $post_type || 'topic' === $post_type ) {
        $forum_id = private_groups_get_forum_id_from_post_id( $post_id, $post_type );
    }

    //Check if current user can view the forum that the post belongs to. 
    if ( false === private_groups_can_user_view_post_id( $forum_id ) ) {
        $user_can_view = false;
    }

    //Filter the search results for forum topics or replies based on the users forum permission. 
    if ( 'reply' === $post_type || 'topic' === $post_type ) {
        if ( $user_can_view ) {
            $post_ok = true;
        } else {
            $post_ok = false;
        }
    }

    return $post_ok; 
}

Your account

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

Search

Popular Resources

Moving the admin search page

Jules Colle came up with a method of moving the Relevanssi admin search page from under the Dashboard heading to the top level of the admin menu. add_action( ‘admin_menu’, function () { remove_submenu_page( ‘index.php’, ‘relevanssi_admin_search’ ); add_menu_page( ‘Search all content’, ‘Search all content’, ‘manage_options’, ‘relevanssi_admin_search’, ‘relevanssi_admin_search_page’, ‘dashicons-search’, 2 ); },……99 ); This function adds an admin_menu action that first uses remove_submenu_page() to remove the existing admin search function and then add_menu_page() to add it again on the top menu level. This works well except for one thing. The Relevanssi admin javascript is added only to specific pages, and the……introduced. This filter hook lets you add new admin page hooks where Relevanssi javascript is used, so we can introduce our new admin search page: add_filter( ‘relevanssi_acceptable_hooks’, function( $hooks ) { $hooks[] = ‘toplevel_page_relevanssi_admin_search’; return $hooks; } ); Now we have a nice, functioning admin search that is not hidden:…

WP Job Manager
Relevanssi doesn’t work with the WP Job Manager search. The solution is fortunately simple: you can just disable Relevanssi for…

Related Posts:

Comment Section:

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