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.
—
by
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.
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.
Sorry- you can skip my comment, right after I posted I found the error. No array
I assume you need this
[code]is_category(array(560,561,562)))[/code]
Yepp,exactly
Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.
Leave a Reply
You must be logged in to post a comment.