WordPress.org

Ready to get started?Download WordPress

Forums

Custom Query to select unique meta_value based on other 'meta_value's (2 posts)

  1. thinkdj
    Member
    Posted 2 years ago #

    I want to populate two dropdowns using post meta. One with all the unique city names and the other with the unique Area names based on what city name was selected.

    meta_value: City, Area

    For getting the list of Unique Cities, I'm using:

    $wpdb->get_col( $wpdb->prepare( "
          SELECT DISTINCT pm.meta_value FROM {$wpdb->postmeta} pm
          LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id
          WHERE pm.meta_key = '%s'
          AND p.post_status = '%s'
          AND p.post_type = '%s'
          ", $key, $status, $type ) );

    Could someone help me with the second custom query required, which will return the list of Areas based on the City Name passed.

  2. thinkdj
    Member
    Posted 2 years ago #

    Wrong forum, my bad.

Topic Closed

This topic has been closed to new replies.

About this Topic