Help with SQL to identify authors by specific role
I’m getting the following error message that I need some help troubleshooting:
“Warning: array_keys() [function.array-keys]: The first argument should be an array in …”
Here is the code that is generating the error message (I put an arrow at the start of the line that is the problem):
global $wpdb, $table_prefix; // set global WP vars needed for script
$order = ‘display_name’; // set order for users table query
$user_ids = $wpdb->get_col(“SELECT ID FROM $wpdb->users ORDER BY $order”); // query users
foreach($user_ids as $user_id) : // start authors’ profile “loop”
$user = get_userdata($user_id); // retrieve author details
$level = $table_prefix . ‘user_level’; // set ‘user_level’ usermeta meta_key record
$user->user_level = $user->$level; // assign ‘user_level’ property to $users
$role = $table_prefix . ‘capabilities’; // set ‘role’ usermeta table meta_key record
(the following line is the one causing the error)
=> $user->role = array_keys($user->$role); // assign ‘role’ property to $user
$user->role = $user->role; // make sure $user->role is not an array
This code generates a page that lets me list all the authors with a role of “contributor” and above, so I can display a photo, bio, and link to their posts, etc. The page renders fine except for the warning message at the top of the page, which I’d like to make go away.
All other code & plugins I found prior to this just LIST authors, and don’t let me use and format specific data from their metadata.
The code is older, so my first thought is that it refers to WP tables or functions that no longer exist, but I looked at my tables in phpMyAdmin and the seem to be the same as referenced in the code.
Any help would be much appreciated!
- The topic ‘Help with SQL to identify authors by specific role’ is closed to new replies.