• 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)
  • try to add a line like this before your code:

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

    https://codex.www.ads-software.com/Function_Reference/WP_Query

    (untested)

    Thread Starter sincewelastspoke

    (@sincewelastspoke)

    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.