Support

Account

Forum Replies Created

  • I get it. How would you suggest to fix this? Should I create a new Date Picker field that will store the date in Ymd format? That will cause a lot of work since all the products already used that field (a lot of products), and that field with that specific format is used in many functions, so will need to re-program a lot of code. Isn’t there any way to manually transform the date in other format, and then sort them ?
    Thank you again for the help.

  • The date field is not a sub field, its only grouped with some other fields. I have checked into DB and the date_end field is stored like I mentioned in this format: 02/April/2022
    I’m sending you an image of the wp_postmeta table to see how it is stored:
    Table example

    That’s why I’ve used this line of code, to remove the backslash and transform the date into Ymd format, but it still isn’t working:

            $args['orderby'] = date('Ymd', strtotime(preg_replace("/\//", " ", 'meta_value')));
    

    To mention that the latest upgrade was from 4.4.2 to 5.11.4.
    I really ran out of ideas how to solve this issue.
    Thanks for the help.

  • I can’t edit my reply so I have to write a new one. I’ve checked into database, and I saw that the custom field date_end is saved in the following format:
    02/April/2022
    So I’ve tried to manipulate and change the code:

    add_filter('woocommerce_get_catalog_ordering_args', 'woocommerce_catalog_orderby');
    function woocommerce_catalog_orderby( $args ) {
        // <- define category slug- returns true or false
            $args['order']    = 'ASC'; // <- order ASC or DESC
            $args['meta_key'] = 'date_end'; // <- _price is meta_value_num's key - required'
            $args['orderby'] = date('Ymd', strtotime(preg_replace("/\//", " ", 'meta_value')));
    
        return $args;
    }

    But again, I don’t have correct ordering.

  • The date_end is one of the fields in the group.
    I think that the problem is the Save Format: dd/MM/yy, because if I create a new Custom field and I set Return Format: Ymd, then the code is working and the products are ordered correctly. I can’t change the save format of my custom field because I have many functions that are using it and If I change it, the site will break.
    How can I convert this in the query, so that this works?
    Also, this field is old (before update of acf plugin), and now I see that If I create a new field Date Picker, the options are different ( instead of Save Format, there is Return Format etc). Right now I’m using version 5.11.4.
    I’m really confused.
    Thanks.

  • The date_end is one of the fields in the group.
    I think that the problem is the Save Format: dd/MM/yy, because if I create a new Custom field and I set Return Format: Ymd, then the code is working and the products are ordered correctly. I can’t change the save format of my custom field because I have many functions that are using it and If I change it, the site will break.
    How can I convert this in the query, so that this works?
    Also, this field is old (before update of acf plugin), and now I see that If I create a new field Date Picker, the options are different ( instead of Save Format, there is Return Format etc).
    I’m really confused.
    Thanks.

Viewing 5 posts - 1 through 5 (of 5 total)