Last active
August 29, 2015 14:06
-
-
Save lunaluna/a32837f1a2a775659dd8 to your computer and use it in GitHub Desktop.
【WordPress】メインクエリをpre_get_postsフックを使って各条件で改変
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'pre_get_posts', 'foo_modify_main_queries' ); | |
function foo_modify_main_queries ( $query ) { | |
if ( is_admin() || ! $query -> is_main_query() ) | |
return; | |
if ( $query -> is_home() ) { | |
$query -> set( 'post_type', 'post' ); // 投稿 | |
$query -> set( 'orderby', 'menu_order' ); // 指定順 | |
$query -> set( 'order', 'DESC' ); // 降順 | |
$query -> set( 'posts_per_page', 10 ); // ページあたり10件ずつ表示 | |
return; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment