WordPress.org

Support

Support » How-To and Troubleshooting » ORDER Posts by Title?

ORDER Posts by Title?

  • Hi,

    I’m using the following to list Posts in a Page:

    <?php if ( $my_query->have_posts() ) : ?>
          <?php while ( $my_query->have_posts() ) :
          $my_query->the_post(); ?>
            <?php
            //necessary to show the tags
            global $wp_query;
            $wp_query->in_the_loop = true;
            $slug = basename(get_permalink());
            ?>
            <li><a href="<?php the_permalink(); ?>"><span><?php the_title(); ?></span></a></li>
        <?php endwhile; ?>

    Is there a way to change the output order of my results?

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    @alchymyth

    Forum Moderator

    try to add a line like this before your code:

    <?php
    global $query_string;
     my_query = new WP_Query($query_string . '&orderby=title');
    ?>

    http://codex.wordpress.org/Function_Reference/WP_Query

    (untested)

    Thanks for the quick reply.

    Unfortunately this also doesn’t work.

    It just leaves a blank space where I hoped the looped list items would appear.

    Current code:

    <?php while ( $my_query->have_posts() ) :
          $my_query->the_post(); ?>
            <?php
            //necessary to show the tags
            global $wp_query;
            $wp_query->in_the_loop = true;
            $my_query = new WP_Query($wp_query . '&orderby=title');
            $slug = basename(get_permalink());
            ?>
            <li><a href="<?php the_permalink(); ?>" class="<?php echo $slug; ?>"><span><?php the_title(); ?></span></a></li>
        <?php endwhile; ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘ORDER Posts by Title?’ is closed to new replies.
Skip to toolbar