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 the correct meta_value with get_post_meta

get_post_meta() is simply just a wrapper for get_metadata(). If we look at the source or get_metadata(), we will find that, if $key is left empty, $single is ignored because of the following lines of code which comes before $single is applied

if ( ! $meta_key ) {
    return $meta_cache;
}

So, in your usecase, $single never gets to do it’s job.

The double key=>value pairs simply means that you have an array of values for that specific key, and the two values in the array are the same value. This is caused by a flaw somewhere in your code which is responsible for saving data to your custom field. You should go and search for that particular piece of code and sort that particular issue.

I cannot tell you which is the correct value and which not, that is something that you also cannot answer. As I said, you will need to sort your code responsible for saving your custom field data.

In the meantime, you can break out of your foreach loop to only get the first value from a custom field, but I do not recommend this as a solution, the solution will involve to sort how you save your custom field data

$postmeta = get_post_meta($resultid, '', true);

foreach ($postmeta as $meta_key => $v) {
    foreach ($v as $kk => $meta_value) {
        echo "$meta_key => $meta_value.\n";
        break;
    }
}

Related Posts:

  1. How to check if post meta key exists or not in wordpress database
  2. How to add category to: ‘wp-admin/post-new.php’?
  3. How can I retrieve multiple get_post_meta values efficiently?
  4. Code to make a post sticky
  5. How to allow hidden custom fields to be added from wp-admin/post.php?
  6. Export WordPress Posts and Meta Information in CSV format
  7. Delete duplicated wp_postmeta record
  8. How to query serialized array by comparing greater than (>=)?
  9. Will a large postmeta table slow a site down?
  10. Update all posts automatically when using post_meta
  11. How to batch update post content with custom post meta value
  12. Change slug with custom field
  13. JSON not valid after json_encode posts
  14. Better post meta efficiency?
  15. Setting post meta data to random value during post status transition / on publish
  16. how to limit and display tag?
  17. Edit meta data does’t work with custom sql
  18. Human Time Diff, change mins to minutes
  19. Change post format using custom field
  20. Does WP get all post_meta on POST page?
  21. Sanitizing `wp_editor();` Values for Database, Edit, and Display
  22. Exporting Data from WordPress into a flat table
  23. Adding Multiple Values to a Post Meta Key
  24. How to update serialized post meta?
  25. Using radio button meta data from a custom meta box
  26. PHP Notice error (when on 404 page)
  27. What Is meta_id In wp_postmeta?
  28. Checking if a post with certain meta value exists
  29. How to permanently delete a post meta entry?
  30. Add custom field automatically (add_post_meta) with value based on number of words of article
  31. How to generate numbers indistinguishable for the IDs of the posts
  32. Modify WP_Post before processing
  33. Save re-arranged draggable post items to wordpress database
  34. I would like to give special promotion for the first 100 posts in my blog? Can anyone tell me how to do that?
  35. Change post_date to post_modified date on post template?
  36. Converting a dynamic piece of code using WordPress Loop into a static one using Post ID
  37. How can I sort posts by the date and a custom meta field?
  38. is there a way to show the the post title after the image?
  39. Get Meta Key Value While Saving Post
  40. Insert woocommerce products programmatically with featured image and gallery
  41. Add multiple tags to multiple posts
  42. Force the “Choose from the most used tags” meta box section to always be expanded
  43. Meta value does not save for scheduled posts
  44. Custom Posts Query and meta_query Sort Order
  45. How to compare two posts including their meta fields on a scalable base?
  46. Featured Images most often doesnt appear
  47. Save / Update meta data as multidimensional array
  48. Post meta not working
  49. Merge get_comments & get_posts into a single query
  50. How to bulk Update URLs to new values?
  51. Select another post in a post meta like a parent page is selected while editing a page
  52. SQL DELETE multiple post_meta on single and multi-sites
  53. Private post caught in endless redirect loop
  54. How to retrieve all meta data directly from the $post object? Such as $post->related_topics?
  55. What is proper filter or hook action to add data to the $post object?
  56. Blogposting Schema & Structured Data without plugin
  57. Automatically select template based on query string for New Posts
  58. Display Updated Date Instead of Published Date
  59. How do you update post date (year only) in a separate custom field?
  60. Add postmeta to all blog posts
  61. Bulk Post update_post_meta
  62. Re-order Category Meta-data
  63. How to hide meta from search result only on pages?
  64. WP_Query sort by meta_value_num or date
  65. Grab meta data before post is saved
  66. How to fetch posts that are stored in the different table than the default table (wp_posts)?
  67. WordPress text field in array problem
  68. Check if user has avatar
  69. alt of attached image in post / pages
  70. Creating Ordered Query using Meta_key
  71. Best Way to detect unique posts in wp rest api
  72. post_name is not stored until post is published… where should I store my slug until it goes live then?
  73. Filter question list on substring of metavalue
  74. Add a meta to a post submited from a frontend form
  75. I am not getting result from php function that is json encoded
  76. Show posts between two Custom Fields date
  77. Add custom class to existing menu items from custom meta
  78. How to get only current images of a post
  79. Ordering posts alphabetically by meta keys and title
  80. Run function after post is updated
  81. Where should get_post_meta() go to get $post->ID get_post_meta() is empty and $post->ID & get_the_id() are working
  82. Get current user array with post string
  83. Adding custom fields to the Quick Edit screen – puzzled about the column concept
  84. Sort Posts Alphabetically by Multiple Categories [duplicate]
  85. Why is $_POST Empty in Profile Edit Admin?
  86. Show related (archive) month and year to post
  87. Exclude a ‘portfolio’ custom category?
  88. How enter custom post meta or custom field on box post list archive page?
  89. WP_query sort by custom meta_key “price”
  90. If meta_key exists then don’t select this post?
  91. posts_per_page – Repeats only first posts ‘post__in’ array
  92. How to create a cumulative posts and members count
  93. NewsPaper WP Theme – Additional Related Posts Filter by Time (divTag composer)
  94. What effect can a large wp_post table have on overall site performance?
  95. Site ‘Categories’: save an admin global setting with post metadata [closed]
  96. How to make internal links creating plugin to respect ACF?
  97. Translation related post text to Arabic
  98. WordPress post meta key and value lookup
  99. How can I create Woodmart theme “linked variations” through REST API?
  100. Parameter for pagination posts_pagination
Categories posts Tags array, post-meta, posts
cant able to upload media to my wordpress blog
Password protected uploaded PDF page

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