0

This is my first question on StackOverflow! I'm a PHP and WP developer beginner, and I'm doing my best to learn and pull information together, but I'm stumped.

I'm using Ninja Forms for WordPress. I want to return a full list of users and have them display in the drop down selection. The code below is based off this: Foreach loop inside array.

$blogusers = get_users( array( 'fields' => array( 'user_email') ) );

$args = array(
        'name' => 'Select User',
        'edit_options' => array(
                array(
                        'type' => 'select',
                        'name' => 'select_users_from_group',
                        'label' => 'Select a User',
                        'options' => array()
                ),
),
        'display_function' => 'select_users_from_group',
        'edit_function' => 'select_users_from_group_edit',
        'sidebar' => 'template_fields'
); 

foreach($blogusers as $key=>$user) {
        $args['edit_options'][0]['options'][] = array(
//      'name' => $user=>user_email,;
        ); 
}

if( function_exists( 'ninja_forms_register_field' ) ) {
        ninja_forms_register_field('select_users_from_group', $args);
}

I know my foreach loop is no good, but I don't know what to do to make it work. It fails when I remove the comment.

Eventually, I'd like for another field to return a user_meta value based on the user selected here, but I have no idea where to even begin on that.

Any help is appreciated. Not looking for you to write it for me. I'd rather learn how it works. Thanks in advance!

Community
  • 1
  • 1
mmcdon8
  • 1
  • 2
  • You should have a helpful syntax error when you execute that code.If you don't see it, take a look at http://stackoverflow.com/q/845021/3794472 and make sure you have error reporting enabled. The problem is a `=` character instead of a `-` in your object property access - see http://php.net/manual/en/language.oop5.properties.php – Jeremiah Winsley Feb 14 '15 at 06:16
  • It's actually a simple typo. Change `'name' => $user=>user_email,;` to `'name' => $user->user_email` (make sure to get rid of that semi-colon and change the second '=>' to '->') – maiorano84 Feb 14 '15 at 06:30

0 Answers0