Forums

Query post is not targeting the correct category (1 post)

  1. meganlee1984
    Member
    Posted 5 months ago #

    I'm building a theme where specific pages pull only one category to display in a list of the loop. I'm trying to specify only one category per custom page, but the loop seems to be pulling in all of the posts still

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    		<div class="entry col3">
    
    				<?php the_content(); ?>
    
                    <?php $custom_query = new WP_Query('cat=6'); // only category 6 music posts
    while($custom_query->have_posts()) : $custom_query->the_post(); ?>
    
    	<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
    		<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
    		<?php the_content(); ?>
    	</div>
    
    <?php endwhile; ?>
    <?php wp_reset_postdata(); // reset the query ?>
    
               </div>

Reply

You must log in to post.

About this Topic