I’m trying to put all the values from a postmeta key into a foreach loop ,
I’ve tried get_post_ meta and get_post_custom but these only seem to work based on a post Id .
Also tried get_post_custom_values but this again only seems to return the current post..?
I just want all the values from a certain meta_key . I’m trying to populate a form dropdown list with the values…?
Any ideas…
This is what i now have;
$results = $wpdb->get_results( "SELECT $wpdb->postmeta.meta_value WHERE $wpdb- >
postmeta.meta_key = 'geo_short_address'" );
$options = array();
foreach ($results as $result) {
$options[$result->meta_value] = ucwords( $meta_value );
}
?>
</select>
<select name="country" id="country">
<option value="selected">Select a location</option>
<?php
foreach ($options as $key => $value) {
?>
<?php $retaincount = $value ?>
<option <?php if ($_GET['country'] == $retaincount ) { ?
>selected="<?php echo $value; ?>" <?php }; ?>value="<?php echo $value ?>">
<? php echo $value?></option>
<?php
}
?>
</select>
<p>
<input type="submit" value="<?php _e('Filter', 'appthemes'); ?>"
class="submit" />
<input type="hidden" name="action" value="Filter" />
</p>
<div class="clear"></div>
</form>
<?php endif;
}
Thanks
I’m pretty sure that you will need a custom MySQL query for that.
Here is something that should work:
Just replace
'custom_key'with your custom field name and that should give you all values for that custom field.I can’t test the code right now, so feel free to tell me if it’s not working.