I am working on a theme at the moment and I have set up a post template.
This post template is linked to some custom post types.
When I query_posts for my post type on the actual post template itself it makes the content disappear for some reason? Is there something I am missing here?
Thanks,
Mark
My loop is as follows:
<?php
$query = 'posts_per_page=10&post_type=articles';
$queryObject = new WP_Query($query);
// The Loop...
if ($queryObject->have_posts()) {
while ($queryObject->have_posts()) {
$queryObject->the_post(); the_title(); the_content();
}
}
?>
use
wp_reset_query
after your loop to restore the global post data for the main loop.For the sake of completeness, while using
wp_reset_query()
isn’t necessarily wrong, it is an unnecesary extra operation, if run after a secondary query with a new instance of theWP_Query
class. The$wp_query
object isn’t altered, so it needs not be reset. Only the$post
global requires a reset. Hence,wp_reset_postdata()
would be sufficient in this case.See /wp-includes/query.php for reference: