Problem with WP_User_Query
-
I have updated my WordPress to the new version 4.0.1 and I got some problems. Before I had an old version, the 3.5.1 and everything was ok with my code. Pardon me for my bad english, I try to explain it.
I have this code:
$user_query = new WP_User_Query(array('ID')); $users = (array) $user_query; ... <select name="UsersZone" class="" style="width: 100%" onChange="setZoneUser(this.value);"> <option value="false">--Select A User--</option> <?php foreach($users["results"] as $user) { ?> <option value="<?php echo $user->ID?>"><?php echo $user->display_name;?></option> <?php } ?> </select>
So, with this code I should have a list of my Users. But I receive this error:
Warning: Invalid argument supplied for foreach() in /web/htdocs/www.mywebsite.com/home/... on line xxx
where xxx is the line
foreach($users["results"] as $user)
I have tried to use var_dump($users) and I got this:
array(8) { ["query_vars"]=> array(17) { ... } ["WP_User_Queryresults"]=> array(1) { [0]=> object(WP_User)#4246 (7) { ["data"]=> object(stdClass)#4244 (10) { ["ID"]=> string(1) "1" ["user_login"]=> string(5) "Admin" ["user_pass"]=> string(34) "xxx" ["user_nicename"]=> string(5) "admin" ["user_email"]=> string(26) "[email protected]" ["user_url"]=> string(0) "" ["user_registered"]=> string(19) "2014-11-26 18:55:12" ["user_activation_key"]=> string(0) "" ["user_status"]=> string(1) "0" ["display_name"]=> string(5) "Admin" } ["ID"]=> int(1) ["caps"]=> array(1) { ["administrator"]=> bool(true) } ["cap_key"]=> string(15) "wp_capabilities" ["roles"]=> array(1) { [0]=> string(13) "administrator" } ["allcaps"]=> array(63) { ... } ["filter"]=> NULL } } ["WP_User_Querytotal_users"]=> string(1) "1" ["query_fields"]=> string(30) "SQL_CALC_FOUND_ROWS wp_users.*" ["query_from"]=> string(13) "FROM wp_users" ["query_where"]=> string(9) "WHERE 1=1" ["query_orderby"]=> string(23) "ORDER BY user_login ASC" ["query_limit"]=> NULL }
So the problem is in the field “WP_User_Queryresults” instead of “results”.
How can I solve this problem? Thank you.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Problem with WP_User_Query’ is closed to new replies.