• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2893

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

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.

Register for full access

Related Posts

  • Use a Plugin to Change Order Of Displaying Post Types

Custom Post Type

Reader Interactions

Comments

  1. Rita says

    August 19, 2017 at 11:24 am

    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.

    Log in to Reply
    • Rita says

      August 19, 2017 at 12:34 pm

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

      Log in to Reply
    • Brad Dalton says

      August 19, 2017 at 1:31 pm

      I assume you need this

      is_category(array(560,561,562)))
      Log in to Reply
      • Rita says

        August 19, 2017 at 2:55 pm

        Yepp,exactly

        Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis & WooCommerce.

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Contact
  • Terms
  • Genesis WP Tags
  • WooCommerce