我已经修改了我的搜索结果页面,其中包含将搜索结果计数更改为 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
找到并尝试了此代码,但它不起作用
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');