Last active
February 9, 2017 05:12
-
-
Save gatespace/f9653653986434cf6e5381f1ed87f433 to your computer and use it in GitHub Desktop.
WordPress 管理画面の投稿一覧にカラムを追加してカスタムフィールドの値を出す ref: http://qiita.com/gatespace/items/199c9995e47d668e0fb0
This file contains hidden or 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
<?php | |
// カスタム投稿タイプ book の投稿一覧で作成者名を削除し、本の著者名を追加 | |
function add_book_columns( $columns ) { | |
// 削除(作成者名) | |
unset( $columns['author'] ); | |
// 追加 | |
$new_columns = array( | |
'book_author' => __( 'Book Author', 'my_theme' ), | |
); | |
$columns = array_merge( $columns, $new_columns ); | |
return $columns; | |
} | |
add_filter( 'manage_book_posts_columns' , 'add_book_columns' ); |
This file contains hidden or 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
<?php | |
// カスタム投稿タイプ book の投稿一覧で日付の前に、本の著者名を追加 | |
function add_book_columns( $columns ) { | |
$new_columns = array(); | |
foreach ( $columns as $column_name => $column_display_name ) { | |
if ( $column_name == 'date' ) { | |
$new_columns['book_author'] = __( 'Book Author', 'my_theme' ); | |
} | |
$new_columns[ $column_name ] = $column_display_name; | |
} | |
return $new_columns; | |
} | |
add_filter('manage_book_posts_columns' , 'add_book_columns'); |
This file contains hidden or 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
<?php | |
// カスタム投稿タイプ book の投稿一覧で 追加した著者名のカラムでその投稿のカスタムフィールド book_author_name を表示 | |
add_action( 'manage_book_posts_custom_column' , 'custom_book_column', 10, 2 ); | |
function custom_book_column( $column, $post_id ) { | |
switch ( $column ) { | |
case 'book_author' : | |
echo get_post_meta( $post_id , 'book_author_name' , true ); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment