spartac (May 16th, 2012)
<?php
function myCustomFucntion() {
global $wpdb;
$query = "SELECT DISTINCT(m.meta_value) ";
$query .= "FROM $wpdb->postmeta m ";
$query .= "WHERE m.meta_key = '_company'";
$query .= "AND p.post_status = 'publish' ";
$query = $wpdb->prepare($query , $meta_key);
$meta_values = $wpdb->get_results($query);
$output = '';
if ( ! empty( $meta_values ) ) {
$output = "<select name='myselectname' id='myselectid'>\n";
$output .= "\t<option value=' '>Select one company bellow</option>\n";
foreach($meta_values as $meta_value) {
$output .= "\t<option value='$meta_value->meta_value'>$meta_value->meta_value";
$output .= "</option>\n";
}
$output .= "</select>\n";
}
return $output;
}
?>
spartac (May 16th, 2012)
$query .= "AND p.post_status = 'publish' ";
<?php echo myCustomFucntion(); ?>
return echo $output;
return $output;
$query .= " AND trim(meta_value) <> '' ORDER BY meta_value ASC ";
$query = $wpdb->prepare($query , $meta_key);
echo $output;
return;
There are currently 1 users browsing this thread. (0 members and 1 guests)