WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Featured Post Category. Im marked some post Featured. When i viewing a category page(e.g. Sport), i want to list on sidebar both marked post list (e.g Featured and Sport,)

I tryed with that following code.It's worked for me but when i using my code i see two category post (e.g Sport ), category post list affected by my code and listing same post list.

My example picture! Here

How can i fix that? My Code:

//55 is my Featured Category id
if ( is_category() ) {
  $current_cat = get_query_var('cat');
query_posts(array('category__and' => array(55, $current_cat )));

if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

        <li><a href="<?php the_permalink(); ?>">
          <?php the_title(); ?>
          </a>  </li>
 <?php endwhile; else: ?>
 <?php endif; ?>
share|improve this question
Are you saying you want one list to be "Sports" and the other list to be "Featured Post"? – Wyck Jan 26 '13 at 0:30
I want to see that, When i view category page(e.g Sports),i want to see Featured and Sport(Current Category)post list on sidebar(widget). its worked with my code but my Sport post list too changing(Featured and Sports) i want to see it just on sidebar.. – Genxer Jan 26 '13 at 0:39
up vote 1 down vote accepted

I think you're asking about your custom secondary loop affecting your main loop, correct?

query_posts() alters the main loop. A quick fix would be to call wp_reset_query() after your custom loop to reset the query data:

<?php wp_reset_query(); ?>

However, it's more efficient and friendlier to use WP_Query() instead of query_posts() (especially if you're making a secondary loop). This should be the equivalent of your provided code using WP_Query():

if ( is_category() ) {
    $current_cat = get_query_var('cat');

$args = array(
    'category__and' => array( 55, $current_cat )

$my_query = new WP_Query( $args );

<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>  
<?php endwhile; ?>

<?php wp_reset_postdata(); ?>




share|improve this answer
It's worked.. Many thanx @BigBagel – Genxer Jan 26 '13 at 0:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.