Sort list of WordPress Page under tag when is_tag() called

I have a site that I’m having so much trouble to try to sort the order of a list of Pages based on their tag.

I’ve build this site over a year ago, with wordpress at the time there isn’t any tag support for Page, so I used the plugin called tags4page. And I believe they still don’t have tag support for pages ? Anyhow, my problem is if you go this page http://www.patentable.com/index.php/lawyers/ the list of Lawyers are in the right order. I can do this with wordpress build in order by giving each page a different weight.

However the problem is if you try to sort the list of Lawyers by selecting the drop down manual it will return a list of lawyers that are belong to this tag that you have selected. PROBLEM is the order are in reversed order for the lawyers. Is there any way to fix this ?

Right now my code is simple, basically is the following:

<?php if (have_posts()) : ?>

<?php /* If this is a tag archive */ if( is_tag() ) { ?>
  <h2>Lawyers in <i><?php single_tag_title(); ?></i> Practice Area:</h2>
<?php } ?>

<?php while (have_posts()) : the_post(); ?>
 <li>
 <a href="https://wordpress.stackexchange.com/questions/5324/<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
 <?php the_title(); ?></a></li>
<?php endwhile; /* rewind or continue if all posts have been fetched */ ?>

1 Answer
1

You could merge order parameters into the query when it’s a tag page..

Replace the following lines.

<?php /* If this is a tag archive */ if( is_tag() ) { ?>
  <h2>Lawyers in <i><?php single_tag_title(); ?></i> Practice Area:</h2>
<?php } ?>

with..

<?php 
if( is_tag() ) { 
    $args = array_merge( 
        array( 'order' => 'asc', 'orderby' => 'title' ), 
        $wp_query->query
    );
    query_posts( $args ); ?>
    <h2>Lawyers in <em><?php single_tag_title(); ?></em> Practice Area:</h2>
<?php } ?>

Leave a Comment