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

Get all metadata for a given custom post type

Your call should include the ID:

get_post_meta($p->ID,"_location",true);

And what is $locations ?
If an array, it should be $locations[] =
If a string, it should be $locations .=

If you only want unique locations, you could do this:

$locations = array();
foreach($posts as $p){
    $location = get_post_meta($p->ID,"_location",true);
    if( ! in_array( $location, $locations) )
        $locations[] = $location;
}

Related Posts:

  1. Advanced search form with filters for custom taxonomies and custom fields
  2. Meta query with boolean true/false value
  3. Get post with multiple meta keys and value
  4. Custom field values deleted when trashing custom post type
  5. How to get all custom fields of any post type
  6. Update CPT meta data using REST API
  7. How do I remove all the metaboxes for a custom post type?
  8. Custom Queries: Joining On Meta Values From Two Custom Post Types
  9. Gutenberg how to make attribute to save to meta
  10. Post metadata deletes itself
  11. Get all posts from custom post type and insert in select input as metabox
  12. WordPress Admin Panel search posts with custom post meta values along with title
  13. How to Update post status using meta data in Custom post TYpe
  14. Rest Api v2 orderby meta_key in custom post type
  15. bulk Update post_meta with default values
  16. How can I include meta box content when searching?
  17. Automatically adding meta data to posts or multiple query help
  18. Trigger “unsaved changes” dialog for custom post meta changes
  19. Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
  20. Add Post Url to Manage Edit Screen
  21. Display all custom post type posts and order them by an optional meta_key
  22. How can I get_post_meta() in the most efficient way?
  23. need advice on how to do a lists using custom post types – taxonomy vs postmeta
  24. Custom Post Status Transition Issues With Get Post Meta
  25. List all images from a single post meta value
  26. orderby in custom WP Query does not work
  27. Show the same Article Available in Other Categories
  28. how to delete all users and posts based on ‘user_meta’?
  29. Meta Key Value in current-user-only loop
  30. How to set YouTube video as featured image?
  31. Notice: Undefined index: error and understanding wordpress
  32. How to implement a Google map store locator
  33. Deleting Custom Posts & Meta Data on Uninstall
  34. Widget: Custom Post Type Post Listing Dropdown on Admin Side
  35. Update Post Meta for a logged in user
  36. How to duplicate entire custom post type
  37. get_post_meta not working on publishing
  38. get_post_meta returning no value in custom post type alert email
  39. WordPress request fiter order by related post’s post_title
  40. Getting thumbnails of a custom posts featured images in a page-templates metabox
  41. Remove Post Custom Meta Box
  42. Show future events based on custom field AND order by date
  43. Using preg_replace to filter custom textarea
  44. If Post Meta Equals Current Title Conditional Advanced Custom Fields
  45. create custom meta box with default value
  46. Issue on Working with Metabox – Checkbox to enable Sale Items
  47. delete_post_meta() for whole CPT / multiple posts?
  48. How to get specific post meta by title or id
  49. How to move a post to different post type with all meta data?
  50. Why do I have to press the “Update” button twice to save my meta box values?
  51. How can I display a drop-down select of Post Names
  52. how to show records that don’t have custom meta value
  53. WP API Response does not show my registered metadata
  54. How to detect that the save_post hook is calling the callback associated to the current edit post page only
  55. WP_Query of custom post type sorted by meta_key has unexpected results
  56. Problem with adding custom post type meta to header by plugin
  57. How to call a post’s metadata in shortcode.php?
  58. Echo custom post meta from options array
  59. Value of post meta dropdown is not showing in WordPress
  60. Advanced custom field – posted fields from custom post type
  61. delete duplicate meta_value with same post_id
  62. Search CPT Title AND Meta
  63. Add a class to post_class if more than one post shares same meta_value_num
  64. Function to return values from metabox
  65. Add a meta field to the list of results for a custom post type
  66. Empty meta-box returns publishdate if no value is set?
  67. Filter search posts by post meta?
  68. Custom Meta Box with variable number of fields
  69. Custom fields for post or terms which don’t update on post update
  70. Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
  71. Add a form in every post and save data in post meta
  72. How to use multiple Meta Field from CPT as Post permalink
  73. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  74. Attaching more than 1 parent (Post) to a media file
  75. How to return/export only data showing on screen in custom post type view all screen
  76. How can I add a meta[] to my custom post type and search by term with the Rest API?
  77. Creating an archive page or simple template to list all values of a custom field of specific post type listing
  78. Custom meta fields not showing up in WP_Response Object via custom endpoint
  79. How to get post by meta value
  80. Get meta values from parent post and save in child post
  81. How do I get all authors posts of a custom post type outside loop
  82. How to Disable option of meta field if that option is selected for any other post in custom post type?
  83. How to get post detail based on URL of the post
  84. Stored meta from attachment, video length?
  85. Custom post type meta fields missing on save_post_type
  86. Linking posts together with Advanced Custom Fields “both ways”
  87. Order posts by meta value hiding posts instead of re-ordering
  88. custom search results – order results differently by post type
  89. How to get Current week and current date record wp query
  90. How to get post meta for custom post type and taxonomy
  91. get_post_meta for Custom Post Type ( CPT )
  92. Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
  93. How to add post reference field to a plugin?
  94. Custom Post Type meta oembed html output resulting in WSoD
  95. Random meta field from specific custom post type
  96. Custom Post Type meta value is being saved in array, instead of just the string (as value)
  97. Custom Form Data save after Login User
  98. Post Meta for Custom Post Types
  99. getEntityRecords/useEntityRecords: How to use CPT metadata?
  100. CPT meta values intermittently return empty
Categories custom-post-types Tags custom-post-types, post-meta
Why does WP_Query have methods that return public properties of the same name
‘delete_option()’ only deleting the value, not the key/value pair

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