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

Retrieving post meta array (attachment)

Your var_dump looks like it’s returning an array because you’re passing false to get_post_meta(). Also you don’t want to print_r() on an echo line.

Retrieve post meta field for a post.

  • $post_id (int) (Required) Post ID.
  • $key (string) (Optional) The meta key to retrieve. By default, returns data for all keys. Default value: ”
  • $single (bool) (Optional) Whether to return a single value. Default value: false
<?php 

$ppics = get_post_meta( get_the_ID(), 'shop_demosc', true );

// if the value is an array of an array, just set to the first array
if( is_array($ppics) && count($ppics) === 1 && is_array($ppics[0]) ){
    $ppics = $ppics[0];
}

foreach ( $ppics as $key => $attachment_id ) {
    $image_url = wp_get_attachment_url( $attachment_id );
    printf( '<img src="https://wordpress.stackexchange.com/questions/245405/%s">', $image_url );
} 

?>   

Related Posts:

  1. How to get meta value in wp_attachment_metadata
  2. What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
  3. Display info from custom fields in all images’ HTML
  4. copy attachments to another post type and change attachment url
  5. Short of raw SQL, can I query for multiple attachment metadata that have a given array key?
  6. Adding meta data to an attachment post
  7. Regenerate missing _wp_attachment_metadata
  8. How to change ID of an attachment in wp_posts and its related tables correctly?
  9. echo image caption
  10. get_post_meta not working on category.php
  11. What are the meta fields for an attachment?
  12. How does WordPress treats attachments metadata in post content?
  13. How can i set media attachments to the author of the post or page for already existed posts with attachments
  14. Attachment metadata has value of ‘1’
  15. Create a Gallery and update Post Parent of Attachment Images
  16. How to append $metadata[‘sizes’] to metadata when using ‘wp_generate_attachment_metadata?
  17. Can I attach image to post without adding it to post?
  18. Remove Dimension from wp_get_attachment_image
  19. Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
  20. post formats – how to switch meta boxes when changing format?
  21. Execute action after post is saved with all related post_meta records (data)
  22. How get post id from meta value
  23. Safe to delete blank postmeta?
  24. Applying automatic link class to images embedded to posts
  25. get_post_meta returning empty string when data shows in the database
  26. publish_post action hook doesn’t give post_meta_data
  27. How to get all term meta for a taxonomy – getting term_meta for taxonomy
  28. How to set author for post AND post attachments
  29. Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?
  30. Should I sanitize custom post meta if it is going to be escaped later?
  31. Making images from single.php pointing to an attachment .php template
  32. Query between two meta values?
  33. copy attachment title to description and alt text
  34. List posts under meta_value heading
  35. wp_get_attachment_image_src always returns false
  36. Exact image sizes
  37. Change default URL of image attachment
  38. Get the size (size in Kb or MB) of an featured image?
  39. Regex to turn embedded images in to attachments
  40. Saving html into postmeta without stripping tags – safe?
  41. How to show Published date and/or Modified date
  42. wp_update_user isn’t instantly?
  43. media_sideload_image with rewritten urls?
  44. Get the bare URL for an attachment
  45. Get thumbnail url of custom meta image?
  46. Exclude featured image from attachment loop
  47. How to use update_post_meta inside wp_trash_post
  48. Display All Custom Post Fields and Values, Unless Empty
  49. Dynamic tagged image galleries
  50. I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?
  51. How to create a meta_query to get all posts with a specific meta data?
  52. Help to upload post attachments from Ajax
  53. Post MetaTable Overload
  54. Custom RSS Feeds & Post Meta Data
  55. get_post_meta not extracting title,permalink and posttype
  56. Display get_post_meta if contains value
  57. Save post meta foreach loop
  58. Should I save this mulit dementional arary as one post meta?
  59. How do you import images from a URL in your post?
  60. Sort Posts By Custom Field Date?
  61. Difficultly changing date format in post meta value
  62. Remove last character in get_post_meta
  63. Uploaded attachment not set as featured image
  64. mass delete posts based on metadata
  65. How to obtain a group of post meta and assign each meta to other variables?
  66. Duplicate rows in meta table, any known relations in WC?
  67. Suggestion to make posts have multiple associated items
  68. update_post_meta in loop changing ALL values
  69. show ad after # paragraphs
  70. Image not showing using a custom function and get_post_meta
  71. How we can get “get_post_meta” of specific user who added it
  72. Randomizing Post Links Outside of Loop – No Author or Date
  73. Excluding post thumbnail from the attachment.php when using wordpress gallery
  74. help to decipher wp metadata
  75. SQL query – get a featured image’s alt / alternative text
  76. I can not display meta value in extras.php and template-tags.php
  77. update_post_meta() updating nested array in Multidimensional array with empty sub-array
  78. Sorting my posts on homepage my specific value in post_meta table
  79. Check if any meta on the post has value then display content
  80. SQL: How to find all attachments that are not used in any posts/pages/custom_post_types
  81. Combine meta query and give a specific meta query a higher priority
  82. How can i show post views using specified post ID?
  83. gettext localization is not working
  84. Move Entry Meta Above Title in Archives (Genesis + Brunch Pro)
  85. How to sort by meta value num, but ignore zero value?
  86. Update event post meta each day automaticaly
  87. Advanced Custom Field — grabbing post_meta from previous post
  88. Issue on Getting WP Gallery Items In cpt-single.php As Attachments
  89. How to create a link for wordpress meta datas?
  90. Which query method to use? (edit- wpdb syntax problems)
  91. Upload unnattached image from frontend
  92. Image attachement management – a philosophical question
  93. wp_get_attachment_link() add rel attribute if the link points to direct image
  94. wp_postmeta store multiple values in one key [closed]
  95. How to link images of one WP site to another WP site?
  96. Save frontend submission form field as custom field
  97. Broken images after importing posts and opening in Gutenberg
  98. Define how an attached image is rendered
  99. Hide individual page title using checkbox in custom meta box?
  100. Footnotes are not copied as a block
Categories post-meta Tags attachments, images, post-meta
What’s the best way to install WordPress?
How to remove “» (title of post or 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