• Resolved davidmontana7

    (@davidmontana7)


    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]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Tijmen Smit

    (@tijmensmit)

    The easiest way is to simply use the internal ID for it since this will be in the same order as the date. So the oldest one will have the lowest ID, and the most recent one the highest ID.

    Change $custom_sort[$key] = $row[‘fax’]; to $custom_sort[$key] = $row[‘id’]; and it should work.

    Do flush the WPSl transient cache on the WPSL settings page ( tools section ).

    Thread Starter davidmontana7

    (@davidmontana7)

    Thank you very much!!
    Saved my life ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Storing them by date’ is closed to new replies.