Q&A
###目的
WordPressの記事一覧で「アーカイブ」または「検索ページ」または「カテゴリー」のときにだけ五十音順に並び替えたいです。
###ためしたこと
次のように書くとエラーでした。
▼functions.php
php
1/*-------------------------------------------*/ 2/* 一覧の並び替え 3/*-------------------------------------------*/ 4function change_posts_per_page($query) { 5 /* 管理画面,メインクエリに干渉しないために必須 */ 6 if ( is_admin() || ! $query->is_main_query() ){ 7 return; 8 } 9 /* 表示条件 */ 10 if ( $query->is_archive() || is_search() || is_category() ) { 11 $query->set( 'posts_per_page', '10' ); 12 $query->set( 'orderby', 'title' ); 13 $query->set( 'order', 'ASC' ); 14 return; 15 } 16} 17add_action( 'pre_get_posts', 'change_posts_per_page' );
どうやら複数条件の指定が悪いようで、
if ( $query->is_archive() || is_search() || is_category() ) {
という複数条件を
if ( $query->is_archive() ) {
と1つの条件にすればアーカイブページでのみ五十音順になります。
どのように書いたら目的のように複数条件で一覧できるのでしょうか?
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
退会済みユーザー
2018/05/24 02:55
退会済みユーザー
2018/05/24 03:06
退会済みユーザー
2018/05/24 03:26