Skip Navigation

[Resolved] Archives not showing proper order

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.

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

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 11 replies, has 2 voices.

Last updated by Shane 6 years, 4 months ago.

Assisted by: Shane.

Author
Posts
#1072596

Hey guys,

I've recorded a video to show you what's the problem.

Here's a link to video: hidden link

#1072649

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ivan,

Thank you for contacting our support forum.

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?

Looking forward to hearing from you soon.

Thanks,
Shane

#1078458

Hello Shane,

Please assist. I have deactivated all plugins that I think could do some damage but none of them seem to work.

Can you please take a look and you have full acces to the site + you can deactivate every plugin you see fit.

Best regards,
Ivan

#1078530

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ivan,

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 ?

Thanks,
Shane

#1080314

Hey Shane,

No problem, what ever you need to solve this.

Thanks a lot

#1083241

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ivan,

Just checking, does the sorting not work for this page only or is it the same across all the custom archive.

Please let me know.

Thanks,
Shane

#1084522

Hey Shane,

None of them seem to work, because it is set to display products by post date, but it still sorts them by alphabetic order.

Thanks,
Best regards,
Ivan

#1084524

Hey Shane,

None of them seem to work, they are displayed/sorted by alphabetic order, not by post date as it should be.

Thanks.

Best regards,
Ivan

#1085848

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ivan,

Could you try remaking this archive page?

There could be something wrong with it why its not working with the sorting because your views work fine.

Thanks,
Shane

#1086529

Hey Shane,

I did it, problem is still there :/
Maybe some WOO conflict?

Thanks.

Best regards,
Ivan

#1088429

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ivan,

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.

I'm still looking into this one for you.

Thanks,
Shane

#1088436

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Ivan,

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.

Thanks,
Shane