1

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 );
                                //var_dump($vote);
                                if($vote=="on"){
                                ?>

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

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


                        </div>

                       <?php } ?>

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks,...oddly enough, removing that line displays nothing. Currently, with the line, it is displaying only the latest of the objects.
Ah so I just removed the break from the code and still get the same result as if I left break in.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.