LoginSignup
0
0

More than 3 years have passed since last update.

カスタム投稿タイプの管理画面にタクソノミー列を追加

Posted at

列に行を追加

functions.php
function add_custom_column( $defaults ) {
$defaults['event_cat'] = 'カテゴリー';
return $defaults;
}
add_filter('manage_event_posts_columns', 'add_custom_column');

'event' : 投稿タイプ
'event_cat' : タクソノミー名

追加した行にタームを追加

functions.php
function add_custom_column_id($column_name, $id) {
if( $column_name == 'event_cat' ) {
echo get_the_term_list($id, 'event_cat', '', ', ');
}
}
add_action('manage_event_posts_custom_column', 'add_custom_column_id', 10, 2);

列の順番を変更

functions.php
function sort_custom_columns( $columns ) {
  $columns = array(
    'cb'     => '<input type="checkbox" />',
    'title'  => 'タイトル',
    'region' => 'カテゴリー',
    'date'   => '日付'
  );
  return $columns;
}
add_filter( 'manage_event_posts_columns', 'sort_custom_columns' );

アイキャッチを表示

functions.php
function add_custom_column( $defaults ) {
$defaults['thumbnail'] = 'サムネイル';
$defaults['event_cat'] = 'カテゴリー';
return $defaults;
}
add_filter('manage_event_posts_columns', 'add_custom_column');

function add_custom_column_id($column_name, $id) {
if( $column_name == 'event_cat' ) {
echo get_the_term_list($id, 'event_cat', '', ', ');
}
if ( 'thumbnail' == $column_name ) {
        $thumb = get_the_post_thumbnail($post_id, array(80,80), 'thumbnail');
        echo ( $thumb ) ? $thumb : '?'; 
    }
}
add_action('manage_event_posts_custom_column', 'add_custom_column_id', 10, 2);

function sort_custom_columns( $columns ) {
  $columns = array(
    'cb'     => '<input type="checkbox" />',
    'title'  => 'タイトル',
    'thumbnail'  => 'サムネイル',
    'region' => 'カテゴリー',
    'date'   => '日付'
  );
  return $columns;
}
add_filter( 'manage_event_posts_columns', 'sort_custom_columns' );
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0