function select_authors_fields( $user ) {
$authors = get_users();
$user_tags = get_the_author_meta( 'select_authors', $user->ID );
?>
<table class="form-table">
<tr>
<th>Select authors:</th>
<td>
<?php
if ( count( $authors ) ) {
foreach ($authors as $author) {
if (user_can($author->ID, 'publish_posts')) { ?>
<p><label for="select_authors_<?php echo esc_attr( $author->ID); ?>">
<input
id="select_authors_<?php echo esc_attr( $author->ID); ?>"
name="select_authors[<?php echo esc_attr( get_the_author_meta('display_name', $author->ID) ); ?>]"
type="checkbox"
value="<?php echo esc_attr( get_the_author_meta('ID', $author->ID) ); ?>"
<?php if ( in_array( get_the_author_meta('ID', $author->ID), $user_tags ) ) echo ' checked="checked"'; ?> />
<?php echo esc_html(get_the_author_meta('display_name', $author->ID)); ?>
</label></p><?php
}
}
} ?>
</td>
</tr>
</table>
<?php
}
add_action( 'show_user_profile', 'select_authors_fields' );
add_action( 'edit_user_profile', 'select_authors_fields' );
// store authors
function select_authors_fields_save( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
update_user_meta( $user_id, 'select_authors', $_POST['select_authors'] );
}
add_action( 'personal_options_update', 'select_authors_fields_save' );
add_action( 'edit_user_profile_update', 'select_authors_fields_save' );
Now the author list appears with checkboxes and it saves my selections. How do I write the query to show the posts from authors I have selected?