• Resolved Javier Carazo

    (@carazo)


    when I have a category with a custom order, the pre_get_posts that is done, disables the ability to sort by date.

    I have solved it by including this in the plugin:

    public function sort_products_by_category( $query ) {
    	if( isset( $_GET['orderby'] ) && $_GET['orderby'] == 'date' )
    		return;
    
    	if ( ( is_product_category() || is_product_tag() ) && $query->is_main_query() && ! is_admin() ) {

    But of course, aside from not wanting to touch the plugin, I’m sure you have a much more elegant way to do it within your own plugin.

    Thank you very much.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Aslam Doctor

    (@aslamdoctor)

    @carazo thanks for finding that bug and posting a fix. I will be checking this today and will publish the updates.

    Thread Starter Javier Carazo

    (@carazo)

    Thanks to you.

    Please check also with other orderby values.

    Surely it only should work with menu-order and also with the default one when menu-order is the default one.

    Plugin Author Aslam Doctor

    (@aslamdoctor)

    @carazo are you using the latest version of the plugin? Because I pushed some updates 2 days ago. I just tested other options on my local setup on categories page by changing orderby option to Price (Low to High) and it seems to work fine. Here are the screenshots.

    Default sort order (Admin): https://prnt.sc/pRmKnFiSMUrd

    Default sort order (Frontend): https://prnt.sc/voPheKkqTNs5

    Price – low to high (Frontend): https://prnt.sc/SV77a4sb6TTG

    I also tested other sorting options like popularity, average rating, latest and all seems to work fine.

    So just need to fix the sort by “Latest” option.

    Thread Starter Javier Carazo

    (@carazo)

    I am a plugin developer. I have always the last version and also, if I make here a question, I only do it if I have the last version.

    Yes, by price for some reason it seems to work but change to “Date” sort. Then it fails.

    Plugin Author Aslam Doctor

    (@aslamdoctor)

    Yep, its just how woocommerce structured the query. Anyway I have published the fix and you will see the version 4.1.5 available to update now.

    Thread Starter Javier Carazo

    (@carazo)

    @aslamdoctor,

    Thanks ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Problems ordering by date in a product category’ is closed to new replies.