Title: Query_posts using multiple custom values (meta_value)
Last modified: August 19, 2016

---

# Query_posts using multiple custom values (meta_value)

 *  Resolved [elandgren](https://wordpress.org/support/users/elandgren/)
 * (@elandgren)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/query_posts-using-multiple-custom-values-meta_value/)
 * Hola!
 * I’ve been trying to generate a query_post call to get a list of posts that have
   2 or more meta_values, but it’s been impossible.
 * Basically, let’s say that all posts have a custom field called “age”.. and I 
   want to get (using query_posts function) all posts which have age=22 and age=
   25.
 * I’ve tried:
    query_posts(‘meta_key=age&meta_value=22&meta_key=age&meta_value=
   25’) query_posts(‘meta_key=age&meta_value=22&meta_value=25’)
 * but, obviously, I’ve got no success… Anyone knows how to solve this?

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/query_posts-using-multiple-custom-values-meta_value/#post-971116)
 * Can’t do that with the [template tag](http://codex.wordpress.org/Template_Tags),
   [query_posts()](http://codex.wordpress.org/Template_Tags/query_posts), custom
   field paramters.
 * You’d have to get all posts with a meta_key=age then filter (if test) in your
   [Loop](http://codex.wordpress.org/The_Loop).
 * Our build a custom query that did that but that’s more complicated. Ref: [Displaying_Posts_Using_a_Custom_Select_Query](http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query)
 *  Thread Starter [elandgren](https://wordpress.org/support/users/elandgren/)
 * (@elandgren)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/query_posts-using-multiple-custom-values-meta_value/#post-971301)
 * Gracias! It’s easier, faster and simplier to adjust my blog to query_post() schema
   instead of diving into mySQL.

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

The topic ‘Query_posts using multiple custom values (meta_value)’ is closed to new
replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [meta_value)](https://wordpress.org/support/topic-tag/meta_value/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [elandgren](https://wordpress.org/support/users/elandgren/)
 * Last activity: [17 years, 4 months ago](https://wordpress.org/support/topic/query_posts-using-multiple-custom-values-meta_value/#post-971301)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
