I have a User Select field on a page and my shortcode is displaying the users on the front-end in ABC order.
I would like them sorted by order in the select field in the backend.
Here is my shortcode
add_shortcode( 'users_by_location', 'users_by_location_func' );
function users_by_location_func() {
if(function_exists('get_field')){
$related_users = get_field('related_users',get_the_ID());
}
print_r($related_users);
}
Thanks for the help!
Willing to pay for help… contact me
I can’t give you a complete answer but I might get you started. In addition to getting the field with
$related_users = get_field('related_users',get_the_ID());
also use
$user_order = get_post_meta($post->ID, 'related_users', true);
This should return an array of user IDs in the order that they are selected. Then you might be able to sort the users in the correct order.
Another option is to simply get the user IDs array as I mentioned above, loop over that and get the information yourself using WP functions instead of depending on ACF. https://developer.wordpress.org/reference/functions/get_userdata/