I need to list out specific custom field items that contain an associated custom field entry. For example, the custom fields are named "type" and "food". I would like to list out all of the breakfast foods. "Breakfast" being the "type" custom field and "bacon", "eggs", "biscuits" being the "food". Right now, I have this query, but it lists out every type of food when I need it to list out only the breakfast types. Would I need to add "WHERE meta_value = 'type' AND meta_key = 'breakfast'" somewhere? I've tried a few places and nothing would work.
<?php
$metakey = 'type';
$stocktypes = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($stocktypes) {
foreach ($stocktypes as $stocktype) {
echo "<option value=\"" . $stocktype . "\">" . $stocktype . "</option>";
}
}
?>