How can I retrieve list of users by author meta field?
-
I am in desperate need of help and I am hoping that somebody can shed some light on where to start.
A certain number of pages on this site are related to departments in this company’s operating structure and need to show contact information for the director assigned to the section that the page is related to. All the directors have been entered into the WP as authors. And since you cannot attach taxonomies to users in WP I have decided to set up an extra text field (“director”) where I can list out the page titles that each author is to appear as a director on.
Everybody with me so far?
I need to be able to retrieve all of the users where the page title matches one of the values in the “director” meta field. My big hurdle in getting this all working is trying to figure out how to put all of the “director” values from all of the authors into an array that I can I can use to run the loop to display the authors.
Would one of you super-mega wordpress experts please help me figure out where to start with this? I have searched the interwebs high and low. There were umpteen places I that describe how to set up custom fields for authors and how to show authors on a page and display their custom meta data, and how to iterate over a list of all the authors on a site, but I have found nothing even closely related to finding authors by meta fields.
This is the code for adding the director field to the user account:
<td> <input type="text" name="director" id="director" value="<?php echo esc_attr( get_the_author_meta( 'director', $user->ID ) ); ?>" class="regular-text" style="width: 492px;" /><br /> <span class="description">Please enter name(s) of the section(s) that the user is director of (separate entries with a comma).</span> </td>
and to save it:
function my_save_extra_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; update_user_meta( $user_id, 'director', $_POST['director'] ); }
- The topic ‘How can I retrieve list of users by author meta field?’ is closed to new replies.