I have tried this code:
<select name="productSize" id="productSize">
<?php
$metakey = 'size';
$sizes = $wpdb->get_col($wpdb->prepare("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($sizes) {
foreach ($sizes as $size) {
echo "<option value="" . $size . "">" . $size . "</option>";
}
}
?>
</select>
But it shows all values with ‘size’ key from all posts. I want to show only the values which associated on each posts. How to do that?
Thank you, really appreciate your help.
Alter $post->ID if required, but by default it will load the current loaded post ID.