Last active
August 29, 2015 13:57
-
-
Save mypacecreator/9406423 to your computer and use it in GitHub Desktop.
特定の条件下で投稿の表示件数を変えたりするアクションフックpre_get_postsのスニペット
This file contains hidden or 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 | |
| function customed_queries ( $query ) { | |
| if ( is_feed() ) { // フィードにカスタム投稿を含める | |
| $query->set( 'post_type', array( 'post', 'gallery' ) ); | |
| return $query; | |
| } | |
| if ( is_admin() || ! $query->is_main_query() ) { //管理画面とサブクエリは対象外 | |
| return; | |
| } | |
| if ( $query->is_main_query() ) { | |
| if ( is_post_type_archive('gallery') ) { | |
| $query->set( 'posts_per_page', 30 ); // ギャラリーのときは30件表示 | |
| } | |
| } | |
| } | |
| add_action( 'pre_get_posts', 'customed_queries' ); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考サイト
http://notnil-creative.com/blog/archives/1996#pre_get_posts