Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8119949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:58:10+00:00 2026-06-06T04:58:10+00:00

I want to only show posts on a wordpress page that belong to logged

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:58:12+00:00Added an answer on June 6, 2026 at 4:58 am

    Something like this should work:

    <?php
        if ( is_user_logged_in() ) :   
            global $current_user;
            get_currentuserinfo();
    
           $query = array('posts_per_page' => '-1','author' => $current_user->ID, 'meta_key' => 'color');
           $result = new WP_Query($query);
    
           while ($result->have_posts()) : $result->the_post(); 
               get_template_part( 'content', 'page', 'the_meta()' );
           endwhile;
        endif;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This page shows many recent posts, instead I want it to show only the
This is for a category index of blog posts-I only want to show the
on an asp.net-mvc website page, i want to show recent blog posts from a
i had installed a wordpress and i want to show the posts in a
I have set my wordpress blog's frontpage to show only three posts. On the
I want to show only desired number of elements in list when I click
I only want to show my title attribute in some cases. I don't want
I have 500 li 's but I only want to show 5 at first,
I have a bunch or markers, and I want to show only the area
By default in all browsers, title attributes only show on mouse over. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.