Add WordPress users to a custom post type

admin2025-01-08  4

I have created a custom post type called Groups. I would like to provide an option to add Users to these groups in the Group edit page. Any help would be appreciated thank you. P.S: I thought of using the Post-to-Post plugin but I am not sure if that would be the right solution.

I have created a custom post type called Groups. I would like to provide an option to add Users to these groups in the Group edit page. Any help would be appreciated thank you. P.S: I thought of using the Post-to-Post plugin but I am not sure if that would be the right solution.

Share Improve this question asked Nov 16, 2018 at 6:31 Sanjana NanjappaSanjana Nanjappa 135 bronze badges 1
  • please check this link i hope this working for you wordpress.stackexchange.com/questions/232887/… – vikrant zilpe Commented Nov 16, 2018 at 7:05
Add a comment  | 

1 Answer 1

Reset to default 0

You can use the ACF plugin for https://wordpress.org/plugins/advanced-custom-fields/.

Steps need to do:

  1. Download and installed ACF plugin.
  2. Click on Custom Fields link at the left side menu
  3. Add custom field as:
  4. Select custom as and publish it:
  5. Now add this code in functions.php file as:
function acf_load_color_field_choices( $field ) {    
    // reset choices
    $field['choices'] = array();
  $blogusers = get_users();
  $field['choices'][0] = "Select User";
  foreach($blogusers as $user){
            // append to choices
            $field['choices'][ $user->ID ] = $user->display_name;
    }
    // return the field
    return $field;    
}
add_filter('acf/load_field/name=select_user_for_post', 'acf_load_color_field_choices');
  1. Now if you create Groups post you will see users list in a dropdown as:

Important details:

  1. get user list

  2. Dynamically populate a select field’s choices

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736270213a1411.html

最新回复(0)