目次
archive.phpでtermの名前を取得する
<?php $term = get_the_terms( $post->ID, 'event-category' ); ?>
<?php echo $term[0]->name; ?>
taxonomy, termの一覧で使用 h2とかで使える
<?php
//taxonomyの一覧h2
$post_type_object = get_post_type_object($post_type);
$post_type_label = $post_type_object->label; //取得結果:'イベント情報'
//termの一覧h2
if(!$post_type_label) {
//termのラベルを取得
$term = get_the_terms( $post->ID, 'event-category' );
$term = $term[0]->name;
$post_type_label = $term;
}
custom post typeで日付順に
function my_func ($wp_query) {
$post_type_array = array('voice', 'work', 'diary');
if ( is_admin() && $wp_query->is_main_query() && in_array($wp_query->get('post_type'), $post_type_array) ){
$wp_query->set( 'orderby', 'date' );
$wp_query->set( 'order', 'DESC' );
}
}
add_action('pre_get_posts', 'my_func');
コメント