0

I'm using a plugin called Anonymous Pro that allows users to submit posts. Users can also submit multiple images into a post, which gets placed in a custom field, like so:

Array ( [0] => http://localhost/image1.jpg,http://localhost/image2.jpg,http://localhost/image3.jpg, )

How would I then display the above images on the frontend?

  • What's the meta_key ? – Zlatev Mar 29 '15 at 10:24
  • The meta_key can be configured to what you want. So at the moment it's AP_post_image – Guit4eva Mar 29 '15 at 10:31
1

Assuming we are viewing some king of single - post, page, custom post type etc.

<?php

$imgs_meta = get_post_meta( get_the_ID(), 'AP_post_image', true );
if ( '' != $imgs_meta ) {
  $imgs = explode( ',', $imgs_meta );

  foreach ( $imgs as $src )
    printf( '<img src="%s" />', esc_url( $src ) );
}
  • Thanks for that. Unfortunately it does not work though, it shows up as: <img src="http://localhost/site/wp-content/uploads/2015/03/image1.jpg,http://localhost/site/wp-content/uploads/2015/03/image2.jpg,http://localhost/site/wp-content/uploads/2015/03/image3.jpg">, and not in individual image tags – Guit4eva Mar 29 '15 at 10:44
  • 1
    Show us output of var_dump( get_post_meta( get_the_ID(), 'AP_post_image' ) ); – Zlatev Mar 29 '15 at 10:51
  • array (size=1) 0 => string 'http://localhost/site/wp-content/uploads/2015/03/image1.jpg,http://localhos‌​t/site/wp-content/uploads/2015/03/image2.jpg,http://localhost/site/wp-content/upl‌​oads/2015/03/image3.jpg' – Guit4eva Mar 29 '15 at 10:55
  • 1
    try code in updated answer – Zlatev Mar 29 '15 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.