Membership Site Search Set-Up Help

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

This topic contains 3 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 years ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #37433
    TonySanGold1
    TonySanGold1
    Participant

    Hello, I hope you are safe and well. I would like to know if you provide any tutorials explaining the best was to use Ajax Pro for use with a multi level membership? I would like to set up specific search instances for each membership level for members to be able to search for Pdfs, audios, videos and courses for their specific membership level. What I don’t know is how to go about setting it up. Can you help? Is there a tutorial that can point me in the right direction. Or could you tell me how to do it. The information would be greatly helpful to me and greatly appreciated.

    Thank You
    Tony

    #37456
    Ernest Marcinko
    Ernest 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.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #37462
    TonySanGold1
    TonySanGold1
    Participant
    You cannot access this content.
    #37475
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    That definitely needs some degree of custom coding – as it is not a WordPress core feature. I researched a bit in our past support tickets, and found one similar query from 2 years ago, where I suggested this code based on the API the customer was able to find:

    add_filter('asp_results', 'asp_fix_groups_exclusions', 10, 1);
    function asp_fix_groups_exclusions($results) {
    	// Group based exclusions
    	if ( class_exists('MeprRule') ) {
    		foreach ($results as $k => &$r) {
    			if ( isset($r->post_type) ) {
    				$post    = get_post( $r->id );
    				if ( MeprRule::is_locked($post) )
    					unset($results[$k]);
    			}
    		}
    	}
    	return $results;
    }

    I don’t know if this worked, because he never responded.

    Searching parts of a single page/cpt object is not possible. In wordpress all posts/cpt are stored as a separate object, thus the plugin can only return them as whole.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.