0
検索結果ページを変更して検索結果の数を10に変更する機能を変更しました。同じことをどうやって行うことができますか?タグ/用語ページの投稿数を10に変更
見つかりfunction change_wp_search_size($query) {
if ($query->is_search) // Make sure it is a search page
$query->query_vars['posts_per_page'] = 10; // Change 10 to the number of posts you would like to show
return $query; // Return our modified query variables
}
add_filter('pre_get_posts', 'change_wp_search_size'); // Hook our custom function onto the request filter
と、このコードを試してみました、それは問題があなたのis_tag()
である
function main_query_mods($query) {
// check http://codex.wordpress.org/Conditional_Tags to play with other queries
if (!$query->is_main_query()) {
return;
}
if (is_tag()) {
$query->set('posts_per_page', 10);
}
}
add_action('pre_get_posts', 'main_query_mods');
これを試してみましたが、この新しい機能を追加すると、投稿カウントは10になりません。 – EmilyG
@EmilyG:私は自分の答えを更新しました。 'wh_tag_search_postCount()'はあなたの投稿数の両方で動作します。 –
検索では10個の投稿が正しく表示されていますが、タグページにはまだ5個の投稿しか表示されていません。 [リンク](https://www.baby-chick.com/tag/pregnancy/) – EmilyG