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`m looking for a solution to dispaly posts in alpahbetical order if category is "Glossary" otherwise display the posts in ascending order. When I tried the following code its works perfect for category Glossary,but the order of other posts went wrong.

<?php global $query_string; 

query_posts($query_string . "&orderby=title&order=ASC");
while ( have_posts() ) : the_post();

query_posts($query_string . "&order = ASC"); ?>
             <?php while ( have_posts() ) : the_post(); ?>
                    <?php  the_title(); ?>

                <?php endwhile; ?>
<?php } ?>

Hope someone will help me to solve the problem.

share|improve this question

First, I would solve your problem using WPQuery. Best to go there as opposed to query_posts

Second, once you acknowledge and accept that WP Query is your friend for as long as you are within the wonderful world of WP theming, then you have to do as follows to solve your particular pickle:

if(is_category('your_category') :
  $args = array(
     'post_type'        => 'post',  
     'posts_per_page'   => 'how_many_posts_you_want_-1_if_all',
      'cat'                 => 'your_category_number',
      'orderby'             => 'title', 
      'order'       => 'ASC'
else :
  $args = array(
    'post_type'         => 'post',  
    'posts_per_page'    => 'how_many_posts_you_want_-1_if_all',
    'order'         => 'ASC'


  $loop = new WP_Query( $args ); 

  while($loop->have_posts()) : $loop->the_post(); 

      //do your magic here



And that ought to do it. You could optimize the $args array a bit as I placed some items on both conditionals, but that can do it for a quick test.

share|improve this answer

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.