WordPress 投稿一覧で項目の並び順を変える

Filed under: functions.php,wordpress — kdcs @ 21年10月9日 土曜日

投稿一覧の並び順を変えたい場合、function.phpに以下を記述

//投稿一覧の並び順を変更する--------------------------------------------------------------
function sort_posts_columns( $columns ) {
  $columns = array(
    'cb'         => '<input type="checkbox" />',
    'title'      => 'タイトル',
    'author'     => '作成者',
    'categories' => 'カテゴリー',
    'tags'       => 'タグ',
    'comments'   => '<div class="comment-grey-bubble" title="コメント"></div>',
    'date'       => '日時'
  );
  return $columns;
}
add_filter( 'manage_posts_columns', 'sort_posts_columns' );

※カスタム投稿タイプの場合(例:itemsというスラッグ)
 カスタム投稿タイプは専用のカテゴリーやタグのスラッグが作られるので、それに合わせる
 add_filter()内のmanage_~もカスタム投稿タイプに合わせる

function sort_posts_columns( $columns ) {
  $columns = array(
    'cb'         => '<input type="checkbox" />',
    'title'      => 'タイトル',
    'author'     => '作成者',
    'items_category' => 'カテゴリー',
    'tags'       => 'タグ',
    'comments'   => '<div class="comment-grey-bubble" title="コメント"></div>',
    'date'       => '日時'
  );
  return $columns;
}
add_filter( 'manage_items_posts_columns', 'sort_posts_columns' );

※重要
なお、デフォルトの投稿タイプにカスタム投稿タイプを追加する場合、
function名が重複しないようにナンバーを付けるか名前を変える

サイト内検索

カテゴリー

最近の投稿

« |WordPress 投稿一覧で項目の並び順を変える| »
↑上に戻る