Advertisement
dimitriskl

Sorting by meta date

Jul 27th, 2020 (edited)
1,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. <?php
  2.  
  3. $job_seeker_experience_fieldset = get_user_meta($job_seeker_id, 'ngoh_usr_experience_fieldset', true);
  4.  
  5. // Sort the array according to most recently STARTED position
  6. function compare_date($a, $b){
  7.     // sort by year
  8.     $retval = strnatcmp($a['started_year'], $b['started_year']);
  9.     // if years are identical, sort by month
  10.     if(!$retval) $retval = strnatcmp($a['started_month'], $b['started_month']);
  11.     return $retval;
  12. }
  13.  
  14. // do the sorting using the processing function
  15. usort($job_seeker_experience_fieldset, __NAMESPACE__ . '\compare_date');
  16. // reverse the array to make it descending
  17. $reversed_experience = array_reverse($job_seeker_experience_fieldset);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement