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

Reply To: Show only when logged in Option

#37367
Ernest MarcinkoErnest Marcinko
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;
}