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. How can I get or the intermediate size of an image with wp_get_attachment_image_src without using post meta?
  18. Some images not being returned with wp_get_attachment_image
  19. Getting meta content from get_next_post & get_previous_post
  20. Check whether attachment ID is associated with more than one post?
  21. Setting name of attachment URL
  22. Change default options on attachment page
  23. How can I hide previous_image_link() on first attachment page?
  24. Incomplete attachment page
  25. Lots of attachments is causing slow load
  26. How to show post attachment image
  27. How can I prevent the post_modified column in wp_posts from being updated?
  28. How to update the ‘modified_time’ of a post ONLY when content is changed?
  29. Media Attachment Custom Meta Fields not saving in Media Uploader when using jQuery UI Autocomplete
  30. How to force attachment size for every post
  31. How do I delete element from a serialized array upon deletion of a post?
  32. How to get pictures of the WordPress post
  33. Sorting meta box values by start- and enddate and all dates in between
  34. How to retrieve “custom url” from image attachment in wordpress
  35. Use an id on a button to update_post_meta in post
  36. When importing posts to a new site if XML file has postmeta not setup on new server what happens?
  37. How to create a link for wordpress meta datas?
  38. Retreive tags from attached post for media on page
  39. Media library orphans
  40. Show title when inserting single images
  41. list of attachments: wp_get_attachment_link works, wp_get_attachment_image does not
  42. Fetch post meta data on POST request
  43. Get value from post meta array, and add it as a category
  44. Adding thumbnails for non-image attachments
  45. Multiple If else statements on Search Result Page
  46. Which query method to use? (edit- wpdb syntax problems)
  47. Using mysql queries to delete custom post types based on meta_value
  48. WordPress join posts with meta values of array type
  49. Get meta information from post parent
  50. Retrieve post data via WPDB class
  51. get_post_meta image width for lazy load
  52. What is the most efficient way to retrieve a group of image URL’s from different attachment ID’s of a specific crop size?
  53. Access Serialized Post Meta Values
  54. delete attachment for one post without deleting actual attachment post
  55. Upload unnattached image from frontend
  56. Write query according to post_meta
  57. Image attachement management – a philosophical question
  58. Custom Fields help
  59. Cache metadata for set of posts
  60. Does post-meta belong in header?
  61. wp_get_attachment_link() add rel attribute if the link points to direct image
  62. How to make certain content of the post noindex and no follow. not entire post?
  63. WordPress Attachments vs Post Meta
  64. How to update post meta with xml data
  65. greater flexibility in targeting images attached to page
  66. Export posts with postmeta without ID?
  67. Stop Attachment image names from taking top level permalink
  68. get_image_tag filter not working
  69. get_children filter with postmeta
  70. How to access & display images from a post without textual content ( and vice versa) according to best wordpress practices
  71. Why values dont shows in custom post column?
  72. get_post_meta of multiple posts?
  73. WP-API : post_meta not updated… but have another entry
  74. Change attachment inside the_content using filters
  75. get_post_custom: get image URL instead of image ID
  76. Counting number of identical meta keys
  77. Parse error thrown by get_post_meta [closed]
  78. How can I display my meta value in a textarea? [closed]
  79. delete blank space in post_meta empty [closed]
  80. getting image alt text via ACF plugin in WordPress [closed]
  81. wp_postmeta store multiple values in one key [closed]
  82. Auto save title as custom meta field value
  83. How to get all the related ids without array?
  84. Remove action of an external plugin after checking if custom post meta is set
  85. How we insert values into database using metabox WordPress?
  86. I am stuck between post meta function to call unique id
  87. How to link images of one WP site to another WP site?
  88. query with custom field
  89. How can we see which posts don’t have a featured image or it doesn’t exist anymore?
  90. Problem with get_post_meta
  91. Using Form to alter PHP variable [closed]
  92. Chance post id into post name
  93. Save frontend submission form field as custom field
  94. How to show wordpress post in the site based on custom field value?
  95. get_post_meta() returns nothing in save_post, publish_post, wp_after_insert_post
  96. Broken images after importing posts and opening in Gutenberg
  97. Image Attachments Query Not Working If Post Is Loaded Via Ajax
  98. wordpress query making site very slow
  99. How can I use an image from an external source without uploading it to the media library
  100. if condition from post_meta not working in save_post
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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