add_action( 'pre_get_posts', 'foo_modify_query_post_order' );
function foo_modify_query_post_order( $query ) {
if ( $query->is_tax('genre') && $query->is_main_query() ) {
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'DESC' );
}
}
add_action( 'pre_get_posts', 'foo_modify_query_post_order2' );
function foo_modify_query_post_order2( $query ) {
if ( $query->is_tax('test') && $query->is_main_query() ) {
$query->set( 'orderby', 'menu_order' );
$query->set( 'order', 'DESC' );
}
}
参考http://gatespace.jp/2012/09/10/modify_main_queries/
<?php
/**
* pre_get_posts を使ってメインクエリーを書き換える
* http://notnil-creative.com/blog/archives/1996
*/
add_action( 'pre_get_posts', 'foo_modify_main_query' ); // pre_get_postsにフック
// フック時に使う関数
function foo_modify_main_query( $query ) {
if ( is_admin() || ! $query->is_main_query() )
return;
if ( $query->is_home() ) { // ホーム
$query->set( 'post_type', array( 'post', 'news' ) ); // 投稿とカスタム投稿タイプ news を含める
return;
}
if ( $query->is_month() ) { // 月別アーカイブ
$query->set( 'posts_per_page', -1 ); // すべて表示
return;
}
if ( $query->is_category() ) { // カテゴリーアーカイブ
$query->set( 'posts_per_page', 10 ); // 10件ずつ表示
return;
}
}