Skip Navigation

[Resolved] order custom taxonomy by post title

This support ticket is created 2 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by chrisC-25 2 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#2478615

I have created a custom taxonomy for my CPT post, the taxonomy is called artist-archive.

I want to be able to view those posts alphabetically. I was able to do this prior by just using the built in categories but now want to use this custom taxonomy and it does not work anymore.

I am NOT using views on this site. Needs to be php. Here is code that was working for category:

add_action('pre_get_posts', 'pre_get_posts_callback');

function pre_get_posts_callback($query){
	
	if(is_post_type_archive('news')) {
		   $query->set( 'order', 'DESC' );
           //Set the orderby
           $query->set( 'orderby', 'POST_DATE' );
	} elseif(is_post_type_archive( 'publishing-roster' ) || is_category(array('pub-artist', 'pub-composer' , 'pub-songwriter')) ){
           $query->set( 'order', 'ASC' );
           $query->set( 'orderby', 'title' );
	} elseif(is_post_type_archive( 'artist' ) || is_category(array('fearless-records-artists', 'concord-jazz-artists' , 'concord-records-artists' , 'craft-recordings-artists' , 'easy-eye-sound-artists' , 'fantasy-records-artists' , 'loma-vista-recordings-artists' , 'rounder-records-artists' , 'featured-artists')) ){
           $query->set( 'order', 'ASC' );
           $query->set( 'orderby', 'title' );
	} 
	
	
}

the is_category part needs to change to something different but what?

I will add links to private message.

Thanks

#2478875

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

To check the taxonomy archive you can use the WordPress native function: is_tax()
=> https://developer.wordpress.org/reference/functions/is_tax/

Can you please try to use this function and check if that help you to resolve your issue.

#2479207

Thanks, I just tried that with no luck, please give me private reply so I can send you a link.

#2479213

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please share problem URL where you want to order posts by post title.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2479447

My issue is resolved now. Thank you!