Home Ask Login Register

Developers Planet

Your answer is one click away!

Chaz February 2016

Issue with PHP loop not displaying all elements

The following code snippet for a wordpress page for some reason is not displaying all of the elements in the this loop. It is only displaying one of the three that are actually returned for $latest_comment. When I console out $latest_comment I get three Obj, all of which I want to run through and display.

Everything looks fine to me but I'm looking with tired eyes. Any help is appreciated. It seems it must be in the if statement following the $latest_comment assignment.

<?php $num_comment=get_comments_number();
                            if($num_comment > 0){ ?>
                            <div class="item-title">
                            <?php $args = array(
                                'number' => 10000,
                                'post_id' => $post->ID,
                                'status' => 'approve'
                            <?php $latest_comment = get_comments($args);
                            //returns 3 Obj which is correct

                            if( $latest_comment ) foreach( $latest_comment as $comment ) { 

                                $vote = get_comment_meta( $comment->comment_ID, 'age1', true );

                            <div class="item-b-l">
                                .....html stuff here....

                            <?php  break; } ?>
                            <?php } ?>


                       <?php } ?>


paranoid February 2016

remove <?php break; } ?> form your code

Post Status

Asked in February 2016
Viewed 3,116 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life