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!

asked Feb 14, 2015 at 0:00
2
  • You should have a helpful syntax error when you execute that code.If you don't see it, take a look at 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 php.net/manual/en/language.oop5.properties.php Commented Feb 14, 2015 at 6: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 '->') Commented Feb 14, 2015 at 6:30

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.