Support » Fixing WordPress » Custom Field Query

  • I sure hope somebody can help me through this one (Please!) …

    I am trying to query the wp_postmeta table for multiple values. For example, I am trying to get the results for entries in the table that have a meta_key of state, a meta_key of city, a meta_value of washington, and a meta_value of Seattle.

    I’m storing data in custom fields, and now I need to query it to get the entries that are basically in Seattle, WA. This would change for each query.

    The problem is that a meta_key can’t have a value of both “state” and “city”…the same problem exists for meta_value.

    I’m creating a website to store information relative to location. What I’m doing is extending the search capabilities to search within a particular city and state, which is why I’m using these custom fields in the first place… 🙂

    I’m using the posts_where filter to run my custom query as noted at: http://codex.wordpress.org/Custom_Queries, but the example that is given assumes that the information is located in a separate table (presumably for the plugin doing this work), not in the wp_postmeta table, which is where I am storing this information…

    You can see the SQL select statement and the search form at: http://www.visitwise.com/?s=Thai&whichCity=mesa&whichState=arizona&key=state

    Again, thanks in advance for any guidance you can offer, I’m at my wits end with this one…

    Thanks!

Viewing 1 replies (of 1 total)
  • Try the answer Otto42 gives in this thread,
    http://wordpress.org/support/topic/161154?replies=10

    Or try searching google for custom fields query two keys

    I am trying to get the results for entries in the table that have a meta_key of state, a meta_key of city, a meta_value of washington, and a meta_value of Seattle….

    The problem is that a meta_key can’t have a value of both “state” and “city”…the same problem exists for meta_value.

    That part of your question is confusing. I would think you don’t have anything with a value of “city” or a value of “state”, those sound like keys not values.

    I think what you’re trying to get is a list of posts with (KEY=State & VALUE=Washington), plus, (KEY=City & VALUE=Seattle). That is do-able.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Field Query’ is closed to new replies.