Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Show only when logged in Option › Reply To: Show only when logged in Option
April 1, 2022 at 12:16 pm
#37367
Keymaster
Hi Dominik,
This only works with custom post types. If you want to exclude taxonomy term results, use this variation instead:
add_filter( 'asp_query_args', 'asp_exclude_only_post_ids', 10, 2 );
function asp_exclude_only_post_ids( $args, $id ) {
/**
* Array of post IDs to exclude for non-logged in users
*/
$post_type_ids = array(1, 2, 3);
/**
* Array of term IDss to exclude for non-logged in users
*/
$tax_term_ids = array(1, 2, 3);
// -- !! Do not change anything below this line !! --
if ( !is_user_logged_in() ) {
$args['post_not_in'] = array_merge($args['post_not_in'], $post_type_ids);
$args['taxonomy_terms_exclude'] = array_merge($args['taxonomy_terms_exclude'], $tax_term_ids);
}
return $args;
}