Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to call a post’s metadata in shortcode.php?

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:

  1. what is the correct way to compare dates in a WP query_posts meta_query
  2. Advanced search form with filters for custom taxonomies and custom fields
  3. Custom field values deleted when trashing custom post type
  4. How to get all custom fields of any post type
  5. Admin Area Custom Type Search By Meta Fields Without Title & Content
  6. How do I Paginate Search Results for Custom Post Types?
  7. How Can I save multiple records in same meta key?
  8. Detect meta value changes when post is updated (post_updated)
  9. Search everything (posts, pages, tags, cpt, meta)
  10. How to get source of custom meta image?
  11. Displaying Meta Box Image
  12. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  13. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  14. Create a random unique 6 digit number as custom field for custom post type
  15. how to interconnect custom post types?
  16. List all images from a single post meta value
  17. Populate Custom Fields in a Custom Post Type?
  18. How to create shortcode to display custom field value on a custom post type
  19. Meta Key Value in current-user-only loop
  20. How to check if user meta field is empty in conditional else statement
  21. How to implement a Google map store locator
  22. Posting to a Custom Post Type from front end – user generated content
  23. Update Post Meta for a logged in user
  24. A better way to add a meta box to custom post types
  25. Two Custom Post Types Many to Many Relationship
  26. get_post_meta not working on publishing
  27. How do I set all of a particular post meta to a value within the custom post type I’m in?
  28. Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
  29. How to render a custom post type template with custom fields using shortcode
  30. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  31. Importing Data from a Non-WordPress database, into WP
  32. Custom fields for custom post type
  33. Check if post with same meta value exists
  34. Submitting Custom Post Types with custom fields from Front-end form
  35. create custom meta box with default value
  36. delete_post_meta() for whole CPT / multiple posts?
  37. How to get specific post meta by title or id
  38. Add custom attributes to a post
  39. copy images from custom field to another custom field
  40. How to show custom field on specific custom post type posts only when filled
  41. Cannot obtain custom meta information
  42. How can I output WPAlchemy repeating fields meta values in my page template?
  43. Trying to write shortcode with get_post_meta but isn’t working
  44. delete duplicate meta_value with same post_id
  45. Search CPT Title AND Meta
  46. updating one custom meta field only
  47. Add a class to post_class if more than one post shares same meta_value_num
  48. Add a meta field to the list of results for a custom post type
  49. Empty meta-box returns publishdate if no value is set?
  50. Filter search posts by post meta?
  51. Custom fields for post or terms which don’t update on post update
  52. Custom Post Type meta data getting deleted on bulk editing taxonomies
  53. Alike Shortcode using in Custom Shortcode
  54. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  55. How to keep custom post type related information
  56. How can I add a meta[] to my custom post type and search by term with the Rest API?
  57. Show posts from WP Custom Post Type selected from a field in a metabox
  58. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  59. Where is get_post_meta value located?
  60. Custom meta fields not showing up in WP_Response Object via custom endpoint
  61. How to Disable option of meta field if that option is selected for any other post in custom post type?
  62. Add more custom fields when creating a new custom post type
  63. How do I extract the contents of a CPT’s custom field for all posts?
  64. Delete custom post type metadata without deleting the post in admin area
  65. How can I get the $key / $value pairs of custom fields that were added via 3rd party plugins or themes?
  66. How to add post reference field to a plugin?
  67. Custom Info Box at end of posts?
  68. Create shortcode for list of custom post titles with custom fields alongside
  69. Advanced search form with filters for custom taxonomies and custom fields
  70. Querying meta values within an array
  71. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  72. Check for custom field value in different post type than current one and do something
  73. Custom Field in Page Title
  74. Why is my select meta data not saving?
  75. dynamically add a custom field or metabox to custom post type [duplicate]
  76. Give a permalink to Custom Post Types without title
  77. Role scoping for contributors down to the field level
  78. Creating a Custom Post as a repository for theme constants
  79. search also in taxonomy, tags and custom fields
  80. Random image from tag/custom type on sidebar
  81. How to stick custom post at the top in search results
  82. Deleting Custom Posts & Meta Data on Uninstall
  83. Widget: Custom Post Type Post Listing Dropdown on Admin Side
  84. How do I create custom fields for multiple post types?
  85. Add field to all custom post types
  86. Query & Order posts by custom fields
  87. Filter custom posts using auto populated dropdown selectors
  88. Post image in WordPress not appearing on home page
  89. How do I associate a custom post type with another through a taxonomy or storing an ID in a custom field?
  90. Custom post type content using custom fields without template
  91. Cannot add custom field to “orderby” parameter in Rest API
  92. How do I create an archive page as a including metadata?
  93. What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
  94. retrieve Meta field value from CPT and set those values as Image Meta Field “Title”
  95. Having unique constraints for custom fields in a custom post type
  96. Querying Two Custom Post Types with OR Not Working
  97. changing meta value and meta key of price field
  98. How can I get the number of custom post type posts that have a specific attachment image set?
  99. Trash / Draft a WordPress custom post after custom date field expires
  100. Set a maxlength for the title input in a custom post type
Categories custom-post-types Tags custom-field, custom-post-types, post-meta, shortcode
Meta box data is saved but NOT displayed in the meta box text field. Why?
Using Grunt and keeping theme comments

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress