Multiple criteria search with custom fields as drop down

Hope I was descriptive enough :slight_smile:

I need your help with something and I’ve spent 3 hours already reading tutorials and trying to understand some stuff. My programming knowledge is close to zero though, so I’m useless.

Here is what I need to do.

I have a page that’s listing various firms from all over the USA. In order for my visitors to be able to use it easier, it should allow them to do some custom searches. They would have a drop-down menu with all the STATES. They choose NY for instance. Then a second drop down menu will list ONLY the cities in the state, so that I don’t list a gazzilion of cities that are in the US. When they have that selected too (New York City for instance), the [search] button should take them to a listing of the New York City firms (the NYC in the NY only, of course - not that there’s another one, but in some cases there can be cities with the same name in different states - I presume).

I have been working from this tutorial:

Here are more details:

The STATE and CITY are custom fields. They are not categories.

I’ll paste now the code I have in functions.php to define those custom fields:

	$posts_array = get_posts( $args );
	foreach( $posts_array as $post ) {	  
  		  $city = get_post_meta($post ->ID, "city");
		  $state = get_post_meta($post ->ID, "state");
        <ul style="margin-left:0px;">
                   <span class="sm_city"><?php print $city[0] ?></span>
                   <span class="sm_state"><?php print $state[0] ?></span>

In the listings page (where I want to be able to do this double criteria searc) I have the following code:

  <select name="city">
  $metakey = 'city';
  $cities = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
  if ($cities) {
    foreach ($cities as $city) {
      echo "<option value=\\"" . $city . "\\">" . $city . "</option>";
  <input type="submit" value="search" />

$cities = $_GET['city'];
if ($cities) {
  $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

    'meta_value' => $cities,

} else {

if ($cities) { ?>
<h1>Your Search For <?php echo $cities; ?></h1>

  <?php }

if (have_posts()) :  while (have_posts()) : the_post();

$event_city = get_post_meta($post->ID, 'city', true); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title();?></a></li>
<?php endwhile;  ?>
<?php else : ?>
<p>Sorry no results were found</p>
<?php endif; ?>

<?php wp_reset_query(); ?>

My problem is that I dno’t know how to make the search function ‘read’ the first selected item in the STATE drop down menu, show in the second drop down menu the cities that are in that state and then display my results from teh STATE + the CITY I have selected.

THANK YOU in advance for any hints :slight_smile: