Home › Forums › General Issues › Sorting woocommerce products by ACF Date Picker field › Reply To: Sorting woocommerce products by ACF Date Picker field
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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.