Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Last active August 29, 2015 14:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kurozumi/cdf100a84f4b634a8cd7 to your computer and use it in GitHub Desktop.
【ワードプレス】管理画面の投稿ページに作成者による絞り込み項目を追加
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