WordPress.org

Ready to get started?Download WordPress

Forums

query_posts and meta_value= (2 posts)

  1. Dgold
    Member
    Posted 5 years ago #

    I'm trying to use query_posts in a multiple loops situation, and I could use some help. I want to query all the posts that have any-value in the Custom Field with Key="Map". I want to display a list of the maps (a list of the custom field values, they are actually hyperlinks to maps) along with other info from the posts like the post title.

    Example,

    Title Of My Post
    Here is my Map: MY CUSTOM FIELD VALUE HERE

    So I'm reading:
    http://codex.wordpress.org/Template_Tags/query_posts#Parameters

    I learned that in WP 2.6+, you can use Custom field Parameters on query_posts like this:

    Custom field Parameters
    Retrieve posts based on a custom field set in the post
    Both the meta_key and meta_value need to be set.
    * meta_key=
    * meta_value=

    My question is, why does the Codex say that BOTH meta_key and meta_value need to be set? I only want to set meta_key=Map. I don't know what the meta_value will be. I want to get the meta_value from the posts that have meta_key=Map. What is the method to say meta_value='anything'?

    By the way, I realize I can do this with a plugin (sort of), like Custom Field Values plugin. I'm trying to learn to do it with query_posts because it would give me more options and flexibility in the way I display it alongside other post data.

    I tried it with just meta_key and without using meta_value, and I think it actually worked, I'm just not sure why the Codex says that.

    Thanks in advance for advice on this!

  2. MichaelH
    Member
    Posted 5 years ago #

    Hey D,

    See revised article for better explaination:
    http://codex.wordpress.org/Template_Tags/query_posts#Custom_field_Parameters

Topic Closed

This topic has been closed to new replies.

About this Topic