Support

Account

Home Forums General Issues Dynamic Populate select options ( User Field )

Solving

Dynamic Populate select options ( User Field )

  • Hi,

    Basically i have an “user field” which allow author to select a list of subscriber and save.
    ———————————————————————-
    <?php acf_form(array(
    ‘post_id’ => ‘user_’.$current_user_id,
    ‘field_groups’ => array(142),
    ‘submit_value’ => ‘Update Subscriber List’
    )); ?>
    ———————————————————————-

    Then what i’m trying to do is populate another select options with the value which
    updated.

    ( the select option will only display subscriber “user_nicename” )

    is there anyway to do this?

  • Need a bit more information. The only thing that I’m sure about is that you have a user field.

    Where is the user field located? on a post, a page, term, etc.

    Where is the other field that you want to populate? Is it another field in the same group or is it a field on another page somewhere?

    What do you want to populate the second field with, exactly the same list of users that’s in the first field, just showing different information? or is it more complicated than then?

  • Hi John,

    First i would like to thank you for replying my topic however i managed to solve it.

    this is how i do
    ———————————————————————————-
    add_filter(‘acf/load_field/name=test1’, function($field) {
    $current_user_id = get_current_user_id();

    global $current_user;
    get_currentuserinfo();

    $field[‘choices’] = array();

    $dynamic_values = get_field(‘my_subscriber’, ‘user_’.$current_user_id);

    foreach($dynamic_values as $dynamic_value => $value) {

    //var_dump($value[‘user_nicename’]);
    $field[‘choices’][ $dynamic_value ] = $value[‘user_nicename’];

    }

    return $field;
    });
    ———————————————————————————-

  • Glad you got it worked out.

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

The topic ‘Dynamic Populate select options ( User Field )’ is closed to new replies.