Thread Starter
cfetr
(@cfetr)
Edit – I am aware that there is a missing closing parenthesis. That is only a typo in this post.
Can you please paste complete index.php.
If it is working with query_posts then it must work with WP_Query.
Thread Starter
cfetr
(@cfetr)
Thanks for your help. I am sure it is something simple that I am missing since I can make query_posts() work.
<?php
global $post;
$postQuery = new WP_Query(array('section_name'=>'campaigns'));
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<div id="campaigns" class="page-content">
<h2 class="page-title"><?php the_title(); ?></h2>
<?php if ( $postQuery->have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( $postQuery->have_posts() ) : $postQuery->the_post(); ?>
<?php //get_template_part( 'content', get_post_format() ); ?>
<div id="post-<?php echo $post->ID; ?>" class="post">
<h3 class="post-title"><?php the_title(); ?></h3>
<div class="post-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; //end the loop ?>
<?php else : ?>
<p>There are no posts to display.</p>
<?php endif; ?>
</div><!-- #campaigns -->
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Try this code:
<?php
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<div id="campaigns" class="page-content"> <?php
$postQuery = new WP_Query(array('section_name'=>'campaigns'));
if ( $postQuery->have_posts() ) : ?>
<?php /* Start the Loop */ ?>
<?php while ( $postQuery->have_posts() ) : $postQuery->the_post(); ?>
<?php //get_template_part( 'content', get_post_format() ); ?>
<div id="post-<?php echo get_the_ID(); ?>" class="post">
<h3 class="post-title"><?php the_title(); ?></h3>
<div class="post-content">
<?php the_content(); ?>
</div>
</div>
<?php endwhile;
wp_reset_postdata(); //end the loop ?>
<?php else : ?>
<p>There are no posts to display.</p>
<?php endif; ?>
</div><!-- #campaigns -->
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
I haven’t tested it, so there may be some syntax error. Please check and revert back.