I want to only show posts on a wordpress page that belong to logged in users AND contain a custom meta key “color.” I have the code for each option i.e. I can either show posts belonging to logged in users or posts with a meta key = color but I cant work out how to combine both so both conditions need to be true. Below are the 2 pieces of code i’m working with:
<!-- If Logged In -->
<?php
if ( is_user_logged_in() ):
global $current_user;
get_currentuserinfo();
$author_query = array('posts_per_page' => '-1','author' => $current_user->ID);
$author_posts = new WP_Query($author_query);
while($author_posts->have_posts() : $author_posts->the_post();
get_template_part( 'content', 'page', 'the_meta()' );
?>
<!-- If Posts Contains Color Meta -->
<?php
$the_query = new WP_Query('meta_key=color');
while ($the_query->have_posts() ) : $the_query->the_post();
endwhile;
?>
Does anyone know how to combine them so posts that match both conditions are shown?
Something like this should work: