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

Excluding a specific role from the search?

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Excluding a specific role from the search?

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #30354
    chief_martin98chief_martin98
    Participant

    Hello,

    Is there a way to exclude results where the author of the post has a certain role?

    I need to exclude a role from appearing in my results. So, the role was ‘Active’, and now ‘Inactive’, but the research results still outputs ‘Inactive’ posts which are irrelevant to the results.

    Can you please help?

    Thanks

    #30362
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

    Well, probably, but only in post process. I recommend the asp_results hook for that. Maybe this custom code would work:

    add_action("asp_results", "asp_exclude_by_role");
    function asp_exclude_by_role($results) {
    	$exclude_role = 'role_name';
    
    	foreach ( $results as $k => &$r ) {
    		if ( isset($r->post_type) && in_array( $exclude_role, ( new WP_User( $r->author ) )->roles ) ) {
    			unset($results[$k]);
    		}
    	}
    	
    	return $results;
    }
    #30364
    chief_martin98chief_martin98
    Participant

    Hi Ernest,

    Excellent, that’s working now. Just to inform you the code was spot on other than it needed to be $r->post_author not $r->author

    Thank you very much for the support.
    Cheers

    #30369
    Ernest MarcinkoErnest Marcinko
    Keymaster

    You cannot access this content.

    #30380
    chief_martin98chief_martin98
    Participant

    You cannot access this content.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Excluding a specific role from the search?’ is closed to new replies.