This thread is resolved. Here is a description of the problem and solution.
Problem:
The issue here is that the user wanted to order their archive page.
Solution:
When creating a custom archive with views you have the option to do the order of the posts being displayed under the order settings for the archive.
If this does not work then you can manually use a hook to do the archive ordering.
Example
add_action( 'pre_get_posts', 'my_change_sort_order');
function my_change_sort_order($query){
if (($query->is_main_query()) && (is_tax('product_cat'))){
//If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type )
//Set the order ASC or DESC
$query->set( 'order', 'DESC' );
//Set the orderby
$query->set( 'orderby', 'title' );
}
};
This support ticket is created 6 years, 5 months 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.
It seems to me that this is being caused by a plugin conflict. Could you temporarily disable all the non-toolset plugins and try again to see if this helps?
I've activated the views debug just to check what is happening with the view query and I found that no matter what i set the sorting to it defaults to wp_posts.post_title ASC in the actual sql query.
Would you mind allowing me to take a clone of this site so that I can debug this further for you ?
I'm thinking that because something is overwriting the archive order query. On a regular view the order works but if you do custom archive for the products then the sorting doesn't work.
It seems we are going to have to manually set the archive sort with some code.
add_action( 'pre_get_posts', 'my_change_sort_order');
function my_change_sort_order($query){
if (($query->is_main_query()) && (is_tax('product_cat'))){
//If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type )
//Set the order ASC or DESC
$query->set( 'order', 'DESC' );
//Set the orderby
$query->set( 'orderby', 'title' );
}
};
The code above should allow you to sort your category by the post title.