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

Custom WP_query help

I'm having problems with my query because I get the same post at my featured post area at the same time at my original wp loop. I'm also having problems with pagination.

I want to ask also if its possible that I can get the first 3 latest post then those post will not be included at my regular wordpress loop post and pagination is still working.

Thank you!

Andrew Shook
Andrew Shook
31,709 Points

Paulette, if you would like help figuring out the problem with your custom wp_query, then it would be helpful for you to post the code that you are currently using. When there is a problem with complicated code like that there could be a dozen of different thing wrong with the code.

As for your second question, yes I do believe it is possible, but I would need to know if the two loops are running on the same page or different pages, and I would need to see both queries that you are using just to make sure.

Yes all the loops are running on the same page. This loops will be viewed in my front page. Thank you Andrew for taking time answering my question :)

<?php

// Loop where I want to post the latest 5 posts.    

$args = array(
    'showposts' => 5    
);

$the_query = new WP_Query( $args ); 

<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <?php get_template_part( 'content', 'page' ); ?>    
<?php endwhile; // end of the loop. ?>

wp_reset_postdata();

?>

<?php

// Loop where I want to show as Featured post the 6th post in the query but having problems achieving that.

$args = array(  
    'showposts' => 6,
    'offset' => 5
);

$the_query = new WP_Query( $args ); 

<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <?php get_template_part( 'content', 'page' ); ?>    
<?php endwhile; // end of the loop. ?>

wp_reset_postdata();

?>

<?php

// Here I'm having problems making pagination work with previews and next pagination at the same time  the wp_pagenavi plugin


<nav>
    <?php previous_posts_link( 'Newer posts &raquo;' ); ?>
    <?php next_posts_link('Older &raquo;') ?>
</nav>

?>