I have 5 custom post types that I am showing at my index page. To do so, I have set five <section>, each one containing a loop that retrieves the last 5 posts of a custom post type, like this:
<?php global $wp_query; query_posts( array( 'post_type' => 'cptx', 'posts_per_page' => 10 ) ); ?> <?php if (have_posts() ) : ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <h1 class="title"> <?php echo get_the_title($ID); ?> </h1> <?php /* Some other metadata, etc.... */?> <?php endwhile; ?> <?php else : ?> <?php get_template_part( 'no-results', 'index' ); ?> <?php endif; ?>
It is working great for the first 4 <section>, but when I get to the fifth, it displays all the posts BUT the ones form that custom post type. The weird thing is I've seen in the database that there is a post from that custom post type, and, before the loop, I have a header for the <section> that outputs the number of posts in the cpt, like this:
<p class="header-postcount"> <?php $count_posts = wp_count_posts('cptx'); echo $count_posts->publish; // ?> </p>
And it displays the correct number (1), even though below it fetches 10 no-cptx posts
What am i doing wrong? Please help!! Thanks!!