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

I cannot display wordpress blogs correctly with order=ASC.

I cannot display wordpress blogs in ASC order. There are 3 blogs in the page and in the second and third blog, I want to display the articles in ASC order. I can display correctly in the second blog but I cannot in the third one. Please help me.

<?php

get_header(); ?>
<!-- site-content -->
<div class="site-content clearfix">

        <?php

        if (have_posts()):
            while (have_posts()): the_post();

            the_content();
            endwhile;
            else:
                echo '<p>No content found</p>';
         endif;

            //opinion posts loop begins here
            $testPosts = new WP_Query('cat=4&posts_per_page=2&orderby=title&order=ASC');

        if ($testPosts->have_posts()):
            while ($testPosts->have_posts()): 
                $testPosts->the_post(); ?>
            <h2><?php the_title(); ?></h2>
            <?php
            endwhile;
            else:
                echo '<p> No content found</p>';
        endif;
        wp_reset_postdata();

        echo 'i';

        //opinion posts loop begins here
            $newsPosts = new WP_Query('cat=9&posts_per_page=2&orderby=title&order=ASC');

        if ($newsPosts->have_posts()):
            while ($newsPosts->have_posts()): 
                $newsPosts->the_post(); ?>
            <h2><?php echo get_the_title(); ?></h2>
            <?php
            endwhile;
            else:
                echo '<p> No content found</p>';
        endif;
        wp_reset_postdata();
        ?>

</div><!-- /site-content -->
<?php get_footer();

?>

1 Answer

problem solved. The first article didn't have a title and that's why it wasn't shown.