WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
up vote 1 down vote accepted

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 ) :
share|improve this answer
Thanks! I'm just doing it as I know how, so any tricks to help do it better are appreciated. – Justice Is Cheap Aug 2 '12 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 Aug 2 '12 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;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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