WordPress.org

Ready to get started?Download WordPress

Forums

ORDER Posts by Title? (3 posts)

  1. sincewelastspoke
    Member
    Posted 3 years ago #

    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

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    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)

  3. sincewelastspoke
    Member
    Posted 3 years ago #

    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; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.