get_the_ID()
can (only) be used within the loop.
This retrieves the ID
of the current post handled by the loop.
You can use it on it’s own if you need it only once:
$dish_meta = get_post_meta( get_the_ID(), 'dish_meta', true );
You can also store it as a variable if you need it more than once:
$post_id = get_the_ID();
$dish_meta = get_post_meta( $post_id, 'dish_meta', true );
$drink_meta = get_post_meta( $post_id, 'drink_meta', true );
print_r( $post_id );
//etc
Reference: get_the_ID()
Related Posts:
- How do I retrieve the slug of the current page?
- How to extract data from a post meta serialized array?
- How to save an array with one metakey in postmeta?
- WordPress is stripping escape backslashes from JSON strings in post_meta
- How to update_post_meta value as array
- What’s the point of get_post_meta’s $single param?
- Get a single post by a unique meta value
- advanced custom fields update_field for field type: Taxonomy
- update_post_meta not saving when value is zero
- Trying to get custom post meta through Jetpack JSON API [closed]
- Restrict post edit/delete based on user ID and custom field
- Why time functions show invalid time zone when using ‘c’ time format?
- Why is get_post_meta returning an array when I specify it as single?
- delete unused postmeta
- Add post meta based on another post meta value before publish post
- WP REST API “rest_no_route” when trying to update meta
- delete value 0 in post meta [closed]
- Can I safely delete a record, manually, in the wp postmeta table?
- What action hook updates post meta?
- Exclude a category from the filed under list
- How do I access post meta data when publishing a new post in Gutenberg?
- Using Advanced Custom Field (ACF) to insert meta description on each page
- Are multiple values from get_post_meta guaranteed to be ordered?
- Add a post metadata if only the key and value does not exist
- Metabox Data not being saved [closed]
- How can I get values using key in Carbon Fields from Multiselect?
- WordPress Action Hooks and Post ID?
- Options to get my custom post type metadata via the WordPress API
- Get page->parent’s name?
- How to get the total number of meta_values based on a custom post type?
- conditional function to change post-meta background image
- Add a meta value if admin , editor or any other user have open a post in edit mode
- Custom meta field don’t give me numerical value
- how to get all post with the same post meta?
- Update Line Item Meta Data – WooCommerce API
- Echo page title from page with custom meta datetime picker
- MySQL Query To Select Post By Postmeta
- Copy content stored in meta to post content
- How to programmatically customise the Contact Form7 notification email prior to sending? [closed]
- Saving repeated option values when querying in Published, draft and all
- How to hide meta block(s) in certain post format
- What type of index should I use for postmeta?
- Get a row from a separate table by matching a posts meta_key to a tables ID column
- need some assistance with the checkboxes (selecting/deselecting featured posts)
- get_post_meta() not work for the first post inside the loop
- Adding new value to existing meta key
- how to get a list of meta data fields assocaited with a custom post type
- Gutenberg: How to display meta field data in the block frontend (save function)
- Reset/delete post views meta/custom field after X hours or minutes or seconds
- String taken from database table post_meta is showing HTML tags on Frontend
- Have lots of meta for posts, is it better to get at all at once or each individually
- Delete posts based on post meta data
- How do I edit the posted “by” and “on” in the post meta
- How to delete duplicate records in wp_postmeta database table?
- Display current user’s custom post meta in sidebar
- update_post_meta() adding bits in database [closed]
- add_post_meta doesn’t work
- Get posts ordered by meta data
- How to get single value from get_post_meta() array of values?
- Displaying values from related field – if empty shows current post type’s link and title
- get_post_meta inside echo [closed]
- WordPress postmeta: Store data as an array or single item?
- wordpress update multiple posts post meta
- Display Post Meta in Header
- get_template_part() isn’t loading author information
- Array of user ids to list of user names
- Conditional For get_the_author_meta
- Custom fields or something else
- get Insert id for meta field
- Format meta_value [closed]
- Count Post and Page Views based on meta_value Using Shortcode in Dashboard Widget
- I want to Add Feedburner Right After Meta Details
- if get_post_meta function returns empty – Do Not Display HTML
- Custom column on CPT not showing correct value when meta data not set
- How to access post meta on the first time a post is published
- I Can’t get the post_tag name from term_id using wp_set_object_terms
- How to update/add child posts meta whenever the parent post meta is updated?
- How to query post with meta?
- why is my postmeta table is so heavy
- update_post_meta() throws Uncaught error: Cannot create duplicate attribute
- get_post_meta and add_post_meta not working
- Using a comma instead of a pipe to separate metadata
- show user based on user_meta
- Multiple meta key and value search in the query
- Meta keys won’t add using wp_insert_post
- Re-pointing images to cloud storage
- undesrtanding get_post_meta function
- How Can I extract Image urls from post meta
- Twenty Twelve entry meta data – change and move
- How can I prevent the post_modified column in wp_posts from being updated?
- Sorting meta box values by start- and enddate and all dates in between
- Use an id on a button to update_post_meta in post
- get_post_meta image width for lazy load
- Custom Fields help
- WP-API : post_meta not updated… but have another entry
- Parse error thrown by get_post_meta [closed]
- How to get all the related ids without array?
- Remove action of an external plugin after checking if custom post meta is set
- wordpress query making site very slow
- if condition from post_meta not working in save_post