php - 用页面 wordpress 填充数组
问题描述
我的网站上有一个产品页面,我有一个数组来存储所有以产品为父级的页面。这工作正常,但由于某种原因,它在 10 个条目后停止填充数组。这是我填充数组的代码。
$args = array(
'post_parent' => get_page_by_path( 'products' )->ID,
'post_type' => 'page',
'numberposts' => -1,
'post_status' => 'any');
// The Query
$parent = new WP_Query( $args );
$n = 0;
// The Loop
if ( $parent->have_posts() ) {
echo '<ul>';
while ( $parent->have_posts() ) {
$parent->the_post();
echo '<li>' . get_the_title() . '</li>';
$n++;
echo $n;
}
echo '</ul>';
// Restore original Post Data
wp_reset_postdata();
}
这将返回页面的标题并回显一个数字来计算它们。输出显示标题,但在 之后停止10 pages
,即使我有12 pages
产品作为父级。奇怪的是,当我添加另一个以产品为父页面的页面时,它会将列表中的最后一个页面推出,并将新添加的页面放在数组的第一个位置。欢迎任何帮助!
解决方案
使用posts_per_page
而不是numberposts
.
$args = array(
'post_parent' => get_page_by_path( 'products' )->ID,
'post_type' => 'page',
'posts_per_page' => -1,
'post_status' => 'any');
推荐阅读
- python - 带有龙卷风的 SNI(服务器名称指示)
- javascript - 获取__definesetter__原函数
- r - R中嵌套列表的直方图
- node.js - 仅在子模式数组中的唯一键?
- repository - Artifactory - 无法上传或看到 DEPLOY 按钮突出显示 - 无法上传 artifact .tar .tgz
- javascript - 条纹导致firebase(网络)中的部署错误
- java - 我可以使用 xslt 让父节点与子节点一起复制吗?
- vb.net - 从 DataTable LINQ 列创建元素列表
- python - jupyter lab replwrap.py ValueError: 找到继续提示
- python - Python Dataframe Groupby 均值和标准差