Skip to content

Instantly share code, notes, and snippets.

@lunaluna
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lunaluna/614787634f3e556673c2 to your computer and use it in GitHub Desktop.
Save lunaluna/614787634f3e556673c2 to your computer and use it in GitHub Desktop.
【WordPress4.0】メインクエリをpre_get_postsフックを使って各条件で改変
<?php
function bar_modify_main_queries ( $query ) {
if ( is_admin() || ! $query -> is_main_query() )
return;
if ( $query -> is_home() ) {
$query -> set( 'post_type', 'post' ); // 投稿
$query -> set( 'orderby', array( 'menu_order' => 'DESC', 'date' => 'DESC' ) ); // 指定順を降順に
$query -> set( 'posts_per_page', 10 ); // ページあたり10件ずつ表示
return;
}
}
add_action( 'pre_get_posts', 'bar_modify_main_queries' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment