Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active Aug 29, 2015
Embed
What would you like to do?
【ワードプレス】管理画面の投稿ページに作成者による絞り込み項目を追加
add_action('restrict_manage_posts', function() {
$selected = ( is_author() ) ? get_query_var( 'author' ) : 0;
$authors = get_users(array('fields' => 'ids'));
printf('<label class="screen-reader-text" for="author">%s</label>', __( 'Filter by author' ));
printf('<select id="filter-by-author" name="author">');
printf('<option value="0">%s</option>', __('All author'));
foreach ( $authors as $author_id ) {
$author = get_userdata( $author_id );
if($selected == $author->ID){
printf("<option value='%s' selected>%s</option>", $author->ID, $author->display_name); }else{
printf("<option value='%s'>%s</option>", $author->ID, $author->display_name);
}
}
printf('</selece>');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment