为什么我的 16 个帖子中只显示了 10 个?
Why are only 10 of my 16 posts being shown?
所以我正在制作一个网站,运行 出现了显示自定义 post 类型的问题。基本上,我有一个名为资源的 post 类型。这些资源分为三个不同的类别:统计、非统计和临床。
这是资源 post 编辑页面的样子。
如您所见,在底部有一个下拉菜单供用户决定观众。这是我用来将资源页面上的资源分类到各个部分的代码。
<?php $args = array(
'post_type' => 'resource',
'order' => 'ASC');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$resource_type = get_field('resource_type');
$audience = get_field('audience');
$forStat = "For Statisticians";
$notForStat = "For Non-Statisticians";
$clinical = "Clinical Trials";
$hasLink = FALSE;
if (get_field(resource_link)){
$hasLink = TRUE;
$resource_link = get_field('resource_link');
} else {
$resource = get_field('resource');
}
?>
<?php if ($audience == $forStat) { ?>
<?php if ($hasLink) { ?>
<a href="<?php echo $resource_link; ?>"><button type="button" class="list-group-item"><?php the_title(); ?></button></a>
<?php } else {
$resourceUrl = $resource['url']; ?>
<a href="<?php echo $resourceUrl; ?>"><button type="button" class="list-group-item"><?php the_title(); ?></button></a>
<?php } ?>
<?php } ?>
<?php endwhile;?>
这是资源页面,因此您可以看到只有 10 post 被显示,尽管有 16 个资源供统计学家使用。 The website resource page.
知道为什么只显示了我创建的前 10 个资源吗?
添加
'posts_per_page' => -1,
作为参数。
$args = array(
'post_type' => 'resource',
'order' => 'ASC',
'posts_per_page' => -1
);
所以我正在制作一个网站,运行 出现了显示自定义 post 类型的问题。基本上,我有一个名为资源的 post 类型。这些资源分为三个不同的类别:统计、非统计和临床。
这是资源 post 编辑页面的样子。
<?php $args = array(
'post_type' => 'resource',
'order' => 'ASC');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$resource_type = get_field('resource_type');
$audience = get_field('audience');
$forStat = "For Statisticians";
$notForStat = "For Non-Statisticians";
$clinical = "Clinical Trials";
$hasLink = FALSE;
if (get_field(resource_link)){
$hasLink = TRUE;
$resource_link = get_field('resource_link');
} else {
$resource = get_field('resource');
}
?>
<?php if ($audience == $forStat) { ?>
<?php if ($hasLink) { ?>
<a href="<?php echo $resource_link; ?>"><button type="button" class="list-group-item"><?php the_title(); ?></button></a>
<?php } else {
$resourceUrl = $resource['url']; ?>
<a href="<?php echo $resourceUrl; ?>"><button type="button" class="list-group-item"><?php the_title(); ?></button></a>
<?php } ?>
<?php } ?>
<?php endwhile;?>
这是资源页面,因此您可以看到只有 10 post 被显示,尽管有 16 个资源供统计学家使用。 The website resource page.
知道为什么只显示了我创建的前 10 个资源吗?
添加
'posts_per_page' => -1,
作为参数。
$args = array(
'post_type' => 'resource',
'order' => 'ASC',
'posts_per_page' => -1
);