Show Posts by Post Title in Alphabetical Order for Custom Post Type Archive

Here’s an example which assumes you have 2 custom post types created , one name portfolio and the other community.

The code simply displays all single pages you publish as custom post types in Alphabetical order in each CPT archive.

Related Posts


Comments

4 responses to “Show Posts by Post Title in Alphabetical Order for Custom Post Type Archive”

  1. I’m trying to make some categories to be sorted alfabethical and the rest by date as is normal. I tried adding this code to the functions.php

    /** Order Posts A-Z on Category Pages **/
    function be_category_query( $query ) {
    if( $query->is_main_query() && $query->is_category(560) && !is_admin() ) {
    $query->set( ‘orderby’, ‘title’ );
    $query->set( ‘order’, ‘ASC’ );
    }
    }
    add_action( ‘pre_get_posts’, ‘be_category_query’ );
    /** end of a-z **/

    It works fine as long as I have only one category -ID but if I have two or more ,
    is_category(560,561,562)
    it still just works for the first category.

    I am using the theme Pretty Creative.

    1. Sorry- you can skip my comment, right after I posted I found the error. No array

    2. Brad Dalton Avatar
      Brad Dalton

      I assume you need this

      [code]is_category(array(560,561,562)))[/code]

      1. Yepp,exactly

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.