This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Membership Site Search Set-Up Help

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Membership Site Search Set-Up Help Reply To: Membership Site Search Set-Up Help

#37456
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Well, I don’t really have any experience with this type of stuff to be honest.

To handle membership levels, I would probably set up a custom field for every user to store the membership level, and the same custom field for the objects which the users would have access to.

Then some custom code would be required to alter the search query arguments – by getting the currently logged in user level, and adding a meta filter to “remove” all of the objects above the user lever from the search results.

add_filter( 'asp_query_args', 'asp_filter_cpt_by_userlevel', 10, 3 );
function asp_filter_cpt_by_userlevel($args, $search_id, $options) {
	$level = get_user_meta( get_current_user_id(), 'my_user_level', true);
	$args['post_meta_filter'][] =  array(
        'key'     => 'my_user_level',
        'value'   => (int)$level,
        'operator' => '<=',
        'allow_missing' => false   // allow match if this custom field is unset
    );
    return $args;
}

In the above example the “my_user_level” user meta is set to set a user level. Then a post meta is also set by the name “my_user_level” to specify the maximum level for a user, which the post/cpt object can be accessed by.