Storing them by date
-
Hello, I needed to show not stores but events on the map and organize them by most recent date first, so I made it easy for me and added the date info into the ‘fax’ field of the CVS and added the following code on functions.php:
// sort by date filter add_filter( 'wpsl_store_data', 'custom_result_sort' ); function custom_result_sort( $store_meta ) { $custom_sort = array(); foreach ( $store_meta as $key => $row ) { $custom_sort[$key] = $row['fax']; } array_multisort( $custom_sort, SORT_ASC, SORT_REGULAR, $store_meta ); //You can reverse the sorting by changing SORT_ASC to SORT_DESC return $store_meta; }
It works, but my problem now is that it’s being sorted by alphanumeric order, so ’01 Apr 20′ comes first and ’01 Feb 20′ comes second. So I uploaded the events again changing the date format from ’12 May 20′ to ‘2020-05-12′ (YYYY-MM-DD) on the CVS file, however I want to add a filter to show it back to ’01 Apr 20’, and I tried this code:
function reformatDate($date, $from_format = 'YYYY-MM-DD', $to_format = 'd F, Y') { $date_aux = date_create_from_format($from_format, $date); return date_format($date_aux,$to_format); }
But it’s not working, I know this is way beyond the scope of the plugin but can you please lend me a hand if you know how to make this work?
Thank you very much
The page I need help with: [log in to see the link]
- The topic ‘Storing them by date’ is closed to new replies.