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!
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)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘WP_Query Showing Restricted Posts’ is closed to new replies.