如果要阻止API生成分页链接,可以使用found_posts
筛选以使WordPress认为当前查询返回的帖子不会超过10篇。
add_filter( \'found_posts\', \'wpd_disable_home_pagination\', 10, 2 );
function wpd_disable_home_pagination( $found_posts, $query ) {
if ( !is_admin() && $query->is_home() && $query->is_main_query() && $found_posts > 10 ) {
return 10;
}
return $found_posts;
}
编辑-
您可以重定向任何分页的URL:
add_action( \'pre_get_posts\', \'wpd_redirect_pagination_urls\', 10, 2 );
function wpd_redirect_pagination_urls( $query ) {
if ( !is_admin() && $query->is_home() && $query->is_main_query() && $query->is_paged() ) {
wp_redirect( get_post_type_archive_link( \'post\' ) );
exit;
}
}