Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9200851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:51:41+00:00 2026-06-17T22:51:41+00:00

The idea: To pull a list of trails in a specific state, or a

  • 0

The idea: To pull a list of trails in a specific state, or a city in a state.

The database table is wp_postmeta, the columns in the table that we will be using are post_id, meta_key, and meta_value.

post_id can be the same in multiple rows
meta_key must either be “location_state” “location_city” or “trail_type”

So go through each row in the database, look for post_meta.meta_value = 'Arizona' and grab the post_id from that same row

THEN foreach post_id it found in that state look for a value in post_meta.meta_key = 'trail_type' with a matching post_id. This means that the post_id is associated with a trail, and not something else. Return an array of the post_id’s which are trails in that state.
to an array called $trails_in_state

Now we have gotten a list of all trails in a state by ID.

I would also like to get all trails in a city of that state into a separate query, so that I can say when the page is hit

<?php if( isset($_GET['city']) AND isset($_GET['state']) ) {
   // GET AN ARRAY OF ALL post_id's OF TRAILS IN THAT CITY STATE COMBO
} elseif( isset($_GET['state'])) {
   // GET AN ARRAY OF ALL post_id's OF TRAILS IN THAT STATE
}

Here is an image of the table structure http://imgur.com/ijhR1NZ

I’m using wordpress so can’t easily use mysqli in this case.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:51:43+00:00Added an answer on June 17, 2026 at 10:51 pm

    I think these should get you started. The first should select you all your post_id’s where you’re meta_value is equal to an input. I’m not sure why you need to limit by state or city a broad match should work just fine. A more specific match to filter on city only would be the 2nd option.

    SELECT trail_type FROM wp_postmeta WHERE post_id=(SELECT post_id FROM wp_postmeta WHERE meta_value=’Arizona’)

    and

    SELECT trail_type FROM wp_postmeta WHERE post_id=(SELECT post_id FROM wp_postmeta WHERE meta_value=’Arizona’ AND meta_key=’location_city’ )

    Failing that you’re either looking at multi selects and sorting or perhaps a UNION query I just can’t get my head around that table structure seems counter intuitive to me 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that I want to pull only certain rows that have
I am using a ScrollView to display a list of items that are inflated
I use IntelliJ Idea with Git. When I pull from repository, I get following
I have a report that takes about 2 or 3 minutes to pull all
Do you have an idea how to pull data from mysql, put it in
I have an idea to streamline deployments of prototypes within our team using VMs.
I have no idea what I'm doing wrong. I am using Twitter Bootstrap with
I've got the code below to pull hex values from a database and create
I have a workflow that will fire once a form field changes. The workflow
I'm loading an HTML template file, which contains templates that I'm using throughout my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.