• Resolved kajori

    (@kajori)


    Hi,

    I have been trying to create a dropdown with only few selected user IDs.
    This is the method I have been using

    // Will provide the list of userIds which we need to show
    $users = $this->get_users_to_display_in_custom_dropdown();
    
     wp_dropdown_users( array(
        'include'          => $users,
        'selected' => ($_POST['user'] ? :    get_current_user_id()),
        'include_selected' => true,
        'show'             => 'user_login',
    ) );

    But the above is showing all the users in the dropdown instead of the ones that is provided to the argument include.

    Is there anything I need to add to show specific users only??

    For a temporary fix I am generating the html manually similar to what wp_dropdown_users will give. The dropdown gets generated but stuck in saving the selected user value for the post.

    Any help will be appreciated. Thanks.

    • This topic was modified 1 year, 11 months ago by bcworkz. Reason: code format fixed
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s likely the $users value is inappropriate for “include”. Inappropriate values are simply ignored. Use var_dump( $users ); to confirm. You want a simple indexed array of only the user IDs as integers. A comma delimited string of integer IDs is also acceptable, but an array is preferred.

    Saving the selection depends on the form handling code and where the information should be saved. You can find generic form handling tutorials for PHP by searching. The examples provided can serve as a starting point, but will need adapting to work within WordPress.

Viewing 1 replies (of 1 total)
  • The topic ‘wp_dropdown_users with the arg include is not working’ is closed to new replies.