Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

TIA!

share|improve this question
add comment

2 Answers

up vote 0 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:

<?php
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 ) :
...
endforeach;
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
add comment

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
add comment

Your Answer

 
discard

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.