Last active
August 29, 2015 14:21
-
-
Save kurozumi/cdf100a84f4b634a8cd7 to your computer and use it in GitHub Desktop.
【ワードプレス】管理画面の投稿ページに作成者による絞り込み項目を追加
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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