Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Trent Burkenpas
Trent Burkenpas
22,388 Points

Wordpress Loop not working

I created a Wordpress loop to loop through some custom posts. It was working fine, but then all of a sudden it stopped. I have no idea why. It will display 1 custom post, but does not show the 4 other custom post. So it's like the loop stops just after one.

here is my code:

<div class="one_half hpeosays animate no-margin" data-anim-type="fadeIn" data-anim-delay="700">

        <h2 class="small">Why Clients <strong>Love Us</strong></h2>

        <div id="owl-demo3" class="owl-carousel small">

            <?php

                $args = array(
                    'post_type' => 'whyclientsloveus'
                );
                $query = new WP_Query( $args );

            ?>

            <?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>

            <div>

                <img src="<?php the_field('picture'); ?>" alt="" />

                <p><?php the_field('testimonial_paragraph'); ?></p>

                <b>- <?php the_field('name_of_client_and/or_company'); ?></b>

                <div class="divider_line21 last"></div>

            </div><!-- end section -->

            <?php endwhile; endif; ?> 

        </div>
    </div><!-- end all section -->

Its inside a slider.

any help would be much appreciated

2 Answers

Sue Dough
Sue Dough
35,800 Points

Sweet dude. Glad I could help. Please mark my answer as best answer if you are happy as I accidentally posted a comment earlier. Yes its common practice. You can go here for more info http://codex.wordpress.org/Class_Reference/WP_Query and google around about the WP Query.

<div class="one_half hpeosays animate no-margin" data-anim-type="fadeIn" data-anim-delay="700">

        <h2 class="small">Why Clients <strong>Love Us</strong></h2>

        <div id="owl-demo3" class="owl-carousel small">

            <?php

                $args = array(
                    'post_type' => 'whyclientsloveus'
                    'showposts' => 5,
                );
                $query = new WP_Query( $args );

            ?>

            <?php if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>

            <div>

                <img src="<?php the_field('picture'); ?>" alt="" />

                <p><?php the_field('testimonial_paragraph'); ?></p>

                <b>- <?php the_field('name_of_client_and/or_company'); ?></b>

                <div class="divider_line21 last"></div>

            </div><!-- end section -->

            <?php endwhile; endif; ?> 

        </div>
    </div><!-- end all section -->
Trent Burkenpas
Trent Burkenpas
22,388 Points

ghost code

Thanks! It worked! I noticed that you just added 'showpost'...

Is that common practice?