I’m assuming you have the add_action
line for this but just in case I provided it in my snippet below.
All in all, it looks like there’s nothing wrong with your version above, but I am wondering if maybe the logic isn’t quite right. Because of that, I’ve separated out some parts below.
add_action( 'pre_get_posts', 'alpha_order_classes' );
function alpha_order_classes( $query ) {
if ( is_admin() ) {
return;
}
if ( ! $query->is_main_query() ) {
return;
}
if ( $query->is_post_type_archive('directory') ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
I am assuming the slug for your post type is simply “directory” too.
Thanks for the quick reply. That function didn’t work either.
The main name and slug is “directory”, we even tried the plural “directories” and the taxonomy “directory_category”.
Still not sure what is missing.
Not sure what to say at this point then, since everything I’ve ever seen with this hook, this above should be working.
Where are you placing the code? Perhaps it’s running too late and thus not doing anything?
Hello,
We redeveloped the page pulling the posts. The query was previously set for DESC and on the new page, we changed it to ASC and all the added posts moved in alphabetical order after saving. We added some more posts and the posts are still in alphabetical order. We greatly appreciate your help.
Hoping we don’t have to display posts alphabetically with a second name field along with title after we import data.
Another quick question. We have used Import any XML or CSV File to WordPress Plugin to import post data on several other website directories. Would that plugin be the best option to work with Custom Post Type UI?
Thanks!
Well like I mentioned, the code above *should* be working, as is.
We should be compatible with any importing plugin, since the only thing CPTUI focuses on is making sure the saved post types/taxonomies are registered when it should be.
Importers deal with the database more than anything we do.