WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Query_posts using multiple custom values (meta_value) (3 posts)

  1. elandgren
    Member
    Posted 5 years ago #

    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?

  2. MichaelH
    Member
    Posted 5 years ago #

    Can't do that with the template tag, query_posts(), custom field paramters.

    You'd have to get all posts with a meta_key=age then filter (if test) in your Loop.

    Our build a custom query that did that but that's more complicated. Ref: Displaying_Posts_Using_a_Custom_Select_Query

  3. elandgren
    Member
    Posted 5 years ago #

    Gracias! It's easier, faster and simplier to adjust my blog to query_post() schema instead of diving into mySQL.

Topic Closed

This topic has been closed to new replies.

About this Topic