Home Forums General Issues Sort User Select field output


Sort User Select field output

  • 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() {
    		$related_users = get_field('related_users',get_the_ID());

    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.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.