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 );
}
?>