Ok, if i understand you clearly, then this is the solution
// first get the post ids that have the breakfast food type
$post_ids = $wpdb->get_col( "SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = 'type' AND meta_value="Breakfast"" );
// now get the food names
$stocktypes = $wpdb->get_col( "SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = 'food' AND post_id IN (". implode(',', array_map('absint', $post_ids) ) .")" );
if ($stocktypes) {
foreach ($stocktypes as $stocktype) {
echo "<option value=\"" . $stocktype . "\">" . $stocktype . "</option>";
}
}
Related Posts:
- Get multiple custom field values in a $wpdb query [duplicate]
- wpdb function insert doesn’t work
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- SELECT max(meta_value) FROM wp_postmeta WHERE meta_key=’price’… stops working when value is over 999
- So much data in postmeta
- What is the advantage of the wp_options design pattern?
- importing data from non-wordpress mysql db
- Query meta field using between
- Move value of one custom field to another
- How to filter a dd/mm/yyyy date from a custom field in a query
- Difference between ‘LIKE’ and ‘IN’ in meta queries
- little help with a mySQL query to wp database
- Importing users to Buddypress with custom fields
- MySQL query to set wp_postmeta using term_taxonomy_id value
- MySQL Query that looks for post with Custom Field, then changes Category
- Unique Post Meta Values
- Add custom field to all posts in specific post_type
- UPDATE on SELECT results. A SQL query to swap Author with Meta Box value
- Custom Query based on custom field of a single post
- Build index page from custom fields
- Importing WordPress Posts With Custom Meta Data As CSV Files Through PHPMyAdmin
- Inserting data into MagicFields using mysql queries
- Copy price categories to custom field
- If I update WordPress my custom data will be deleted from the wp_users table?
- Get emails from users by custom field SQL
- Update post meta data (custom field) by post link
- How to improve my non-unique metadata MySQL entries?
- What is the correct way to search 3 custom fields only in WordPress?
- Delete a custom field in mysql for all posts with specific category id
- Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title
- use mysql to replace one custom field value with another custom field value
- Update custom table on metabox POST
- ACF plugin and field update
- Query postmeta values, and return multiple post_titles for common meta value
- Query Custom Fields in Searchform
- Copy url from post_content to custom field
- Convert many posts from having a specific meta_key to use a post_format
- Custom Search, MySql Query Gone Wrong?
- Site uses wpdb to fetch meta_keys but just displays first meta_key from a page (the post uses the same meta_key “filmmaker” more than once)
- Can running a WP-Cron to update_post_meta cause performance issues?
- to create a custom post type with additionnal url field such as link to social network and an email field
- How To connect to the same WordPress database with different database user
- Create Meta boxes dynamically
- Custom field group on page
- How to save array option as text and not integer?
- Outputting custom field on home.php not outside of blog list
- $wpdb post type and term query only works when there are no dashes or spaces in the term slug and title
- Custom Fields Not Working In Footer
- How to delete attachments associated with custom field type when post property changes? [closed]
- How to repeate custom field group with bulk image field
- Load one page with parent and child pages
- Output Custom Field value to shortcode
- Why can’t I get the correct post permalink
- Get link picker custom field to show only if field exists
- PHP and Shortcode Combination
- Use a different catalog image than the featured image
- Sub Field of File Field
- ACF – Compare user and post data
- Login Api with Meta_key and Meta_value
- Advanced Custom Fields deleting some code and adding code for a slider
- Save input form on custom field
- CONCAT_WS in custom sql query
- Retrieving and inserting data in custom fields
- How to add custom fields to images for image source text and URL
- Counting number of images from loop
- Include a custom field in mysql query
- Page template is missing fields or is invalid when I updating the template
- User custom meta delete by serialised key value
- Metabox value for post loop?
- Adding fields to attachment – only shows when inserting new attachments
- Order categories by sum of custom fields
- how to modify a field’s size in a metabox : ROWS height, and scroll control?
- Add commentmeta custom field to every published comment with SQL
- Saved Post Meta Array Returns as String
- How to add content with a filter when there’s no content in the editor
- Login_form add to top of form rather then bottom
- meta_query ‘compare’ => ‘!=’ not working
- Advanced Custom Fields from Category – IF statement
- Check for meta data before it is published
- Query Multiple meta
- If metabox fields has content display content
- I have a form with a custom button ,i want to add the field data to an database when clicking the custom button
- Stop truncation of shortcodes in custom text fields?
- Delete custom meta
- custom field images do not display until page save
- How to check custom fields from functions.php
- MySQL query in WordPress with AJAX
- Save custom post data outside of default post form
- display custom media folders to wordpress media popup
- Should I store arrays in custom fields or create custom tables?
- Get custom field outside wordpress loop on new php page
- Retrieving Advanced Custom Field within Shortcode Function [closed]
- Query Posts based on custom field value
- How to format the various types of custom fields?
- Problem saving meta data
- How to properly get popular Posts by multiple Values
- Geographical proximity query using post_meta
- Admin – Search Events by a custom field
- How to add a default field Name to post Custom Fields
- Get file size from ACF repeater field