• This isn’t a support question per se, it’s probably a “How can I … ?”

    https://www.relevanssi.com/knowledge-base/restricting-search-for-non-logged-in-users/

    The link above show that you don’t have to have 2 different search indexes. Or atleast that’s what I get out of it. However what I want to do is slightly different from this use case:

    I have three TYPES of users: Open, Free, & Paid. With the Free & Paid Users, they should see a specific set of results. While the Open user would see a slightly different set of results. Both sets share 90% of the same results, with the exception of one post type and one custom post type (CPT) as shown below…

    The Open Users sees the posts in POSTS + CPT:TANGOTHOUGHTS + CPT:DEFINITIONS + CPT:GLOSSARY -> EXCEPT CPT:MEMBERPOSTS.

    The Free & Paid Users sees posts in MEMBERPOSTS + CPT:TANGOTHOUGHTS + CPT:DEFINITIONS + CPT:GLOSSARY -> EXCEPT POSTS

    Is your product capable of doing this ?

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Add a filter function on relevanssi_modify_wp_query, check the status of the user and adjust the post_type parameter according to that.

    add_filter( 'relevanssi_modify_wp_query', 'rlv_user_levels' );
    function rlv_user_levels( $query ) {
        if ( this is an open user ) {
            $query->set( 'post_type', array( 'post', 'tangothoughts', 'definitions', 'glossary' );
        } else {
            $query->set( 'post_type', array( 'memberpost', 'tangothoughts', 'definitions', 'glossary' );
        }
        return $query;
    }

    Something like that.

    Thread Starter magicmiles

    (@magicmiles)

    Wow!!! That’s cool. I honestly didn’t think that was possible. But, clearly, it is.

    Hmmm, ok, I think that has to go in the theme function page. But the open user thing…would probably be best defined as logged in or logged out, no ? And if I wanted to write that and use that as the modifier, it would look like ???

    Miles.

    • This reply was modified 5 years, 12 months ago by magicmiles.
    Plugin Author Mikko Saari

    (@msaari)

    You can use this for the if clause to check for logged-out users:

    if ( ! is_user_logged_in() ) {

    Theme functions.php is a good place for this, yes.

    Make sure all the necessary post types are indexed by Relevanssi.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Different Searches for Different User Types’ is closed to new replies.