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
Access only to all free tutorials per month.
Tutorial Request
Includes code guarantee and coding support.
Access to 10 premium tutorials per month.
Tutorial Request
Includes code guarantee and coding support.
Access to 15 premium tutorials per month.
Monthly Tutorial Request
Includes code guarantee and priority coding support.
Was This Tutorial Helpful?