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

Restrict search results to roles

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Restrict search results to roles

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #49240
    netsuonetsuo
    Participant

    Hi,

    Is there any way to restrict certain results to a user role ? We have private PDF that we want to make searchable but don’t want the results to be shown to non-customers.
    Thanks

    #49256
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi!

    It is very likely possible, but some custom code will be required, depending on how these roles are set. I found a previous topic, where someone else had a similar request, and this custom code was suggested:

    add_filter( 'asp_results', 'asp_filter_posts_by_capability', 10, 1 );
    function asp_filter_posts_by_capability( $results ) {
    	foreach ($results as $k => &$r ) {
    		if ( !current_user_can('read_post', $r->id) )
    			unset($results[$k]);
    	}
    	return $results;
    }

    This however may need to be edited with the correct capability or a function to check if the user is a customer.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.