I have the following code that I can't get working. I have two cloneable fields that are being output as one entity (URL and thumbnail image). These are cloned fields using the Meta Box Plugin by Deluxe Blogging, so I need to be able to do an if statement if there is nothing at all and then I need to be able to repeat the thumbnail and URL twice (if there are two separate entries).

<?php if 
$videoID = get_post_meta( $post->ID, '_danieltiger_repvid', true );
$videoThmb = get_post_meta( $post->ID, '_danieltiger_repthmb', true );
    foreach ( $videoID as $value )
            echo '<div class="video-pops">';
            echo '<a class="thumb video-pop-lb" data-video-pid="';
            echo $videoID;
            echo '">';
            echo '<span></span>';
            echo '<img width="157" height="88" alt="<?php the_title(); ?> image" src="';
            echo $videoThmb;
            echo '" /></a>';
            echo '</div>';
        } ?>

<?php } ?>

The example code from Deluxe Blogging on outputting cloned fields is the following:

$metas = get_post_meta( get_the_ID(), 'meta_key', true );
    foreach ( $metas as $meta )
         echo $meta;

I can't seem to figure out how to work in the two separate values. I have another field I'm cloning and outputting in my theme correctly but I just can't get the gist on this one.


2 Answers 2


amit helped you out, but while we're at it you really shouldn't be echoing everything like that. Should probably try this instead:

foreach ( $videoID as $value ) { ?>
    <div class="video-pops">
        <a class="thumb video-pop-lb" data-video-pid="<?php echo $videoID; ?>"></a>
<?php } ?>

And so on.

You may even be better off using the alternate syntax;

foreach ( $videoID as $value ) :
  • Thanks! I'm just doing it as I know how, so any tricks to help do it better are appreciated. Commented Aug 2, 2012 at 17:22
  • Hey we all start somewhere, right? I did the same thing when I first started off, but you'll grow to love the alternate syntax, it's much clearer (in my opinion).
    – Gilipe
    Commented Aug 2, 2012 at 18:21

Set the last paramter as false to return multiple values for same custom field. Read more about parameters you can use for this function.

$metas = get_post_meta( get_the_ID(), 'meta_key', false );
    foreach ( $metas as $meta )
         echo $meta;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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