You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

wp_list_pages()忽略层级自定义文章类型child_of参数问题及修复

更新 - 已修复,是拼写错误

我的参数数组中,child_of的数组键末尾多了一个空格。我没有修改原帖,以便通过谷歌访问此处的用户参考。

原问题

我想要展示属于特定父ID的层级自定义文章类型(capability_type为'page')的条目。

该自定义文章类型通过functions.php中的以下代码生成:

function custom_post_type() {
    $args = array(
        'supports'              => array( 'title', 'editor', 'comments', 'page-attributes' ),
        'hierarchical'          => true,
        'capability_type'       => 'page',
        'publicly_queryable'    => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'public'                => true
    );
    register_post_type( 'wiki', $args );

}
add_action( 'init', 'custom_post_type', 0 );

我尝试用以下代码仅展示特定ID的子条目:

$ultraparentID = 123;
wp_list_pages(array(
    'child_of ' => $ultraparentID,
    'post_type' => 'wiki',
));

但这段代码列出了wiki自定义文章类型的所有条目,而非仅ID为123的指定子条目。我可能遗漏了文档中的某些内容。根据参数文档,child_of的说明如下:

仅显示单个页面(按ID)的子页面。默认值0(所有页面)。

尽管该函数名为wp_list_pages(),但它应该适用于层级自定义文章类型条目(文档中也有说明)。

我遗漏了什么?或者我的代码中存在什么我没发现的错误?

内容的提问来源于stack exchange,提问作者FLBln

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 23:31:04