Skip to main content
9 events
when toggle format what by license comment
Aug 10, 2016 at 16:34 history edited Pat J CC BY-SA 3.0
linkified "anonymous function"
Aug 10, 2016 at 7:21 vote accept NielsPilon
Aug 9, 2016 at 15:21 comment added Pat J I'm guessing that's because create_function() expects a string, not an actual PHP function, as its final parameter. See my edit (using an anonymous function).
Aug 9, 2016 at 15:21 history edited Pat J CC BY-SA 3.0
added a version using an anonymous function
Aug 9, 2016 at 14:45 comment added NielsPilon Probably missing a single quote somewhere but this usort($users, create_function( $a_last_name = array_pop( explode( ' ', $a->last_name ) ); $b_last_name = array_pop( explode( ' ', $b->last_name ) ); return strnatcasecmp( $a_last_name, $b_last_name ); )); returns a syntax error, unexpected '', $a->last_name ) )'' (T_CONSTANT_ENCAPSED_STRING)
Aug 9, 2016 at 14:18 comment added Pat J ...or you can put the contents of the wpse_235438_sort_users() function into your existing create_function() call.
Aug 9, 2016 at 14:16 comment added Pat J Sorry, I meant to say that you need to separate the usort() callback function (ie, function wpse_235438_sort_users( $a, $b )) from the function where you're calling it from. I usually have a section of "helper functions" in my functions.php file, and that's where my usort() callbacks go.
Aug 9, 2016 at 14:08 comment added NielsPilon Tried that but it returns: Warning: usort() expects parameter 2 to be a valid callback, function 'wpse_235438_sort_users' not found or invalid function name. I added the function to my functions.php file.
Aug 9, 2016 at 14:02 history answered Pat J CC BY-SA 3.0