你错过了一个s。
$query->set(\'posts_per_page\', \'1\');
然而,您可能不希望对每个查询都这样做,因为这会影响所有内容—小部件、后端和所有内容。你应该让它有条件。例如:
<?php
function university_adjust_queries($query) {
// If this is the main query, not in wp-admin, and this is the homepage
if($query->is_main_query() && !is_admin() && $query->is_home()) {
$query->set(\'posts_per_page\', \'1\');
}
}
add_action(\'pre_get_posts\', \'university_adjust_queries\');
?>
这将确保您只影响主页上的主查询(循环),并且只影响前端。您可以调整条件,以针对您想要影响的任何位置。