看起来您正在尝试在“事件”模板上创建辅助存档/索引页,但尚未修改该页的主查询。否则,您将只能获得一页的结果。尝试:
function events_wpse_206465($qry) {
if (is_page(\'events\') && is_main_query()) {
$qry->set(\'posts_per_page\',5);
$qry->set(\'post_type\',\'events\');
}
}
add_action(\'pre_get_posts\',\'events_wpse_206465\');
或创建新查询:
$args = array(
\'post_type\' => \'events\',
\'posts_per_page\' => 5,
);
$myq = new WP_Query($args);
if ($myq->have_posts()) {
while ($myq->have_posts()) {
$myq->the_post();
the_title();
// and so on
}
}