Title: Query posts by custom fields, conditional query
Last modified: August 19, 2016

---

# Query posts by custom fields, conditional query

 *  [eian00](https://wordpress.org/support/users/eian00/)
 * (@eian00)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/query-posts-by-custom-fields-conditional-query/)
 * Hello
 * what am I trying to do is query all posts containing the same custom fields, 
   but only if they satisfy ALL custom fields in the query..
 * example:
 * the normal query :
 *     ```
       <?php query_posts('meta_key=color&meta_value=black
       &meta_key=shape&meta_value=circle&orderby=title&order=asc');  ?>
   
         <?php while (have_posts()) : the_post(); ?>
   
        <a href="<?php the_permalink() ?>"><?php the_title(); ?></a>&nbsp;,&nbsp;
   
         <?php
          global $wp_query;
          $postid = $wp_query->post->ID;
          echo get_post_meta($postid, 'color', true);
         ?>
   
         <?php endwhile;?>
       ```
   
 * with this query i got all the posts containing the custom field value “black”
   OR “circle” but I want to display the post link just in case it has got exactly
   the two values, and not only one.
 * How should the code look for that?
 * Thank you

The topic ‘Query posts by custom fields, conditional query’ is closed to new replies.

## Tags

 * [conditional](https://wordpress.org/support/topic-tag/conditional/)
 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [display](https://wordpress.org/support/topic-tag/display/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [eian00](https://wordpress.org/support/users/eian00/)
 * Last activity: [15 years, 11 months ago](https://wordpress.org/support/topic/query-posts-by-custom-fields-conditional-query/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
