The first one doesn’t work because $post
doesn’t exist inside the context of your shortcode function, you would need to add global $post;
before it. However…
You should use get_the_ID()
instead of accessing the $post
global directly. The reason it doesn’t work in your second example is that it’s not a class method, it’s just a function, and $post
is just a simple object (plus, it doesn’t exist anyway! you have the same problem as the first version above).
Always develop with debugging enabled and your blank white screen will then show error messages to tell you what’s wrong.
So, the working version should be:
get_post_meta( get_the_ID(), 'destination', true );
Related Posts:
- what is the correct way to compare dates in a WP query_posts meta_query
- Advanced search form with filters for custom taxonomies and custom fields
- Custom field values deleted when trashing custom post type
- How to get all custom fields of any post type
- Admin Area Custom Type Search By Meta Fields Without Title & Content
- How do I Paginate Search Results for Custom Post Types?
- How Can I save multiple records in same meta key?
- Detect meta value changes when post is updated (post_updated)
- Search everything (posts, pages, tags, cpt, meta)
- How to get source of custom meta image?
- Displaying Meta Box Image
- ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
- Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
- Create a random unique 6 digit number as custom field for custom post type
- how to interconnect custom post types?
- List all images from a single post meta value
- Populate Custom Fields in a Custom Post Type?
- How to create shortcode to display custom field value on a custom post type
- Meta Key Value in current-user-only loop
- How to check if user meta field is empty in conditional else statement
- How to implement a Google map store locator
- Posting to a Custom Post Type from front end – user generated content
- Update Post Meta for a logged in user
- A better way to add a meta box to custom post types
- Two Custom Post Types Many to Many Relationship
- get_post_meta not working on publishing
- How do I set all of a particular post meta to a value within the custom post type I’m in?
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- How to render a custom post type template with custom fields using shortcode
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- Importing Data from a Non-WordPress database, into WP
- Custom fields for custom post type
- Check if post with same meta value exists
- Submitting Custom Post Types with custom fields from Front-end form
- create custom meta box with default value
- delete_post_meta() for whole CPT / multiple posts?
- How to get specific post meta by title or id
- Add custom attributes to a post
- copy images from custom field to another custom field
- How to show custom field on specific custom post type posts only when filled
- Cannot obtain custom meta information
- How can I output WPAlchemy repeating fields meta values in my page template?
- Trying to write shortcode with get_post_meta but isn’t working
- delete duplicate meta_value with same post_id
- Search CPT Title AND Meta
- updating one custom meta field only
- Add a class to post_class if more than one post shares same meta_value_num
- Add a meta field to the list of results for a custom post type
- Empty meta-box returns publishdate if no value is set?
- Filter search posts by post meta?
- Custom fields for post or terms which don’t update on post update
- Custom Post Type meta data getting deleted on bulk editing taxonomies
- Alike Shortcode using in Custom Shortcode
- Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
- How to keep custom post type related information
- How can I add a meta[] to my custom post type and search by term with the Rest API?
- Show posts from WP Custom Post Type selected from a field in a metabox
- Creating an archive page or simple template to list all values of a custom field of specific post type listing
- Where is get_post_meta value located?
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- How to Disable option of meta field if that option is selected for any other post in custom post type?
- Add more custom fields when creating a new custom post type
- How do I extract the contents of a CPT’s custom field for all posts?
- Delete custom post type metadata without deleting the post in admin area
- How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
- How to add post reference field to a plugin?
- Custom Info Box at end of posts?
- Create shortcode for list of custom post titles with custom fields alongside
- Advanced search form with filters for custom taxonomies and custom fields
- Querying meta values within an array
- Display a list of posts whose meta field values are equal to the ID of the post being viewed?
- Check for custom field value in different post type than current one and do something
- How to Add Custom Fields to a Custom Post Type?
- Custom Taxonomy Template Post List with Sort Order
- Display Custom Post Type Fields
- WordPress query by multiple Custom fields and order by date
- Using ‘strtotime’ function to convert a custom-meta-box to a date-stamp
- Frontend posting – everything saves other than checkboxes?
- handling csv data with a custom post type
- Problem fields custom date, time, and checkbox
- Insert Multiple Post with Same Publish Button
- Sorting custom post type columns with external data and without meta values
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Display Child Pages of Custom Post Type Parent Page
- wp_reset_postdata() and wp_reset_query() inside shortcode are not working to reset original page query
- How to Echo Metadata Value in Currency Format
- how to create custom post type with dynamic category_name using shortcode
- Meta box data is saved but NOT displayed in the meta box text field. Why?
- Confusion about how to use Custom Post Types, Custom Taxonomy or Category?
- Displaying Posts Using a Custom Query with a Custom Field and a term_id
- How to sort WP_Query by a custom text field (written as a date dd/mm/yyyy)
- Auto update publish date of CPT Post if default post custom field value match to cpt post CF Value
- Create Inclusions and exclusions
- Retrieving custom post type fields without a post
- pre_get_posts with multiple post types AND a meta_key
- Search form to find custom meta box generated data
- WordPress custom post type
- Show Custom Post Type taxonomy term that matches custom field
- Custom Post Type + Custom Meta Query Not Showing 2012 Posts