user3181828
user3181828

Reputation: 381

Sort posts by name in Wordpress

For some reason, no matter what I do, nothing seems to work to put these posts by alphabetical order. The code is:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
array( 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC' ); 
 ?>
<li>
<div class="sponsor-thumb">
<a href="'.get_permalink().'">
<?php the_post_thumbnail( 'category-thumb' ); ?></a></div>
<a href="<?php the_permalink() ?>">
<?php the_title(); ?>
</a></li>
<?php endwhile; else: ?>
    <p><?php _e('Sorry, this page does not exist.'); ?></p>
<?php endif; ?>   

Upvotes: 0

Views: 7270

Answers (1)

BIOSTALL
BIOSTALL

Reputation: 1696

Putting that code where you have it is having no effect on the query.

To achieve what you want you want to use WP_Query like so:

$args = array( 'posts_per_page' => -1, 'orderby'=> 'title', 'order' => 'ASC' ); 
$my_query = new WP_Query( $args );
if ( $my_query->have_posts() ) : 
   while ( $my_query->have_posts() ) : $my_query->the_post(); 
      // do stuff here
   endwhile; 
endif;

Upvotes: 3

Related Questions