Home » Ask (Forum) » How to Displaying a Custom Post Type Alphabetically

Question

Hi, in my site I have custom post type. I’m trying to get the loop of custom post types to display in alphabetical order, but having no luck. I’ve tried various plugins and other solutions, but most only allow manual sorting 🙁

Any help appreciated.

Sep 12, 2016 (3 months ago) - Posted by 1 Comment

One Answer

  1. Support says:

    What is your custom post type name? Can you add more information, please!

    You should add something like this in your code:

     $args = array(
           'post_type' => 'book',
           'posts_per_page' => -1,
           'orderby' => 'title',
           'order' => 'ASC'
        );

    Or like this:

    <?php 
    $args = array( 'post_type' => 'book', 'posts_per_page'=>5, 'orderby'=>'title','order'=>'ASC');
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    ?>

    Remember you must using order and orderby in your arguments.

    Good luck!

    Team Support

Your Answer

Your email address will not be published. Required fields are marked *