Title: WP_Query Showing Restricted Posts
Last modified: August 30, 2023

---

# WP_Query Showing Restricted Posts

 *  Resolved [kokoruz](https://wordpress.org/support/users/kokoruz/)
 * (@kokoruz)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/wp_query-showing-restricted-posts/)
 * I am querying and filtering my posts using 2 custom taxonomies. What I discovered
   today is the posts that I have restricted from non-logged-in display are having
   their posts titles show up in my wp_query. How do I query my posts to exclude
   the posts that I have restricted to be only available to logged in users. On 
   a positive note when I click the permalink of the queried title it does redirect
   to the login but I don’t even want the posts to be visible unless the user is
   logged in. Thank You!
 *     ```wp-block-code
       function country_product_query(array $country_terms, $operator1, $product_terms, $operator2) {
   
       	if ($operator1 === null) {
               $operator1 = 'IN';
           }
       	if ($operator2 === null) {
               $operator2 = 'IN';
           }
   
       $term = get_term_by('slug', $product_terms, 'product_categories');
       $term_name = $term->name;  
   
       $args = array(
       	// Arguments for your query.
       	'post_type' => array('post', 'page'),
       	'posts_per_page' => -1,
       	'tax_query' => array(
       		'relation' => 'AND',
       		array (
       			'taxonomy' => 'locations',
       			'field' => 'slug',
       			'terms' => $country_terms,
       			'include_children' => false,
       			'operator' => $operator1
       		),
       		array (
       			'taxonomy' => 'product_categories',
       			'field' => 'slug',
       			'terms' => $product_terms,
       			'include_children' => false,
       			'operator' => $operator2
       		)
       	)
       );
   
       $the_query = new WP_Query( $args );
       if ( $the_query->have_posts() ) {
   
   
   
       	echo '<strong>' . $term_name . '</strong>';
       	echo '<ul>';
           while ( $the_query->have_posts() ) {
               $the_query->the_post();
       		the_title( '<li><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></li>' );
           }
       	echo '</ul>';
           wp_reset_postdata();
   
   
       }
       }
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Support [Kim L](https://wordpress.org/support/users/kimmyx/)
 * (@kimmyx)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/wp_query-showing-restricted-posts/#post-17022737)
 * Hi [@kokoruz](https://wordpress.org/support/users/kokoruz/),
 * It’s currently not possible to hide a restricted post from an archive page.
 * Our development team is currently working on a new version of Content Control
   with new features, and this is one of the things on their list.
 * For now, you might want to try the solution offered here: [categories – How to hide a specific category posts in my monthly archive? – WordPress Development Stack Exchange](https://wordpress.stackexchange.com/questions/40857/how-to-hide-a-specific-category-posts-in-my-monthly-archive)
 * Hope it helps! Let us know if you have more questions. 😊
 *  Plugin Author [Daniel Iser](https://wordpress.org/support/users/danieliser/)
 * (@danieliser)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/wp_query-showing-restricted-posts/#post-17034368)
 * [@kokoruz](https://wordpress.org/support/users/kokoruz/) I’ll add that we are
   super close, very likely within 1 week of releasing v2.0.
   You can test out a 
   demo at [https://app.instawp.io/launch?t=content-control-v2-beta-test-sites&d=v2](https://app.instawp.io/launch?t=content-control-v2-beta-test-sites&d=v2)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘WP_Query Showing Restricted Posts’ is closed to new replies.

 * ![](https://ps.w.org/content-control/assets/icon-256x256.gif?rev=2968535)
 * [Content Control - The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More](https://wordpress.org/plugins/content-control/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/content-control/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/content-control/)
 * [Active Topics](https://wordpress.org/support/plugin/content-control/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/content-control/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/content-control/reviews/)

## Tags

 * [restricted](https://wordpress.org/support/topic-tag/restricted/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * 2 replies
 * 3 participants
 * Last reply from: [Daniel Iser](https://wordpress.org/support/users/danieliser/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/wp_query-showing-restricted-posts/#post-17034368)
 * Status: resolved