如何修改自定义帖子类型的‘post_parent’?

时间:2011-02-10 作者:Manny Fleurmond

我希望能够编辑自定义帖子类型的post\\u父级。基本上在我的用例中,我想模仿WordPress使用附件的方式:有一个自定义的post类型,它是post的子类型或任何其他post类型。WordPress使用wp\\u posts表上的post\\u parent字段将附件链接到其父帖子,因此我希望能够执行相同的操作。我曾尝试使用wp\\u update\\u posts,但在保存post时尝试调用它时,连接似乎超时。有没有办法直接编辑post\\u父级?

2 个回复
最合适的回答,由SO网友:MikeSchinkel 整理而成

你好@Manny Fleurmond:

您可以将以下HTML添加到post metabox 您将有一个编辑字段,用于编辑原始post_parent ID.也许有了这些知识,你可以构建你需要的东西?

<input type="text" id="parent_id" name="parent_id" 
       value="<?php echo $post->post_parent; ?>" />

SO网友:Giovanni Putignano

如果我完全理解这个问题,那么您可以在注册CPT时设置对页面属性的支持,如下所示:

add_action( \'init\', \'register_products_post_type\' );
function register_products_post_type() {
    $labels = array(
        \'name\' => \'Products\'
    );

    $args = array(
        \'labels\'        => $labels,
        \'public\'        => true,
        \'rewrite\'       => array(
            \'with_front\'    => false
        ),
        \'has_archive\'   => true,
        \'hierarchical\'  => true,
        \'menu_position\' => 5,
        \'supports\'      => array( ..., \'page-attributes\', ... )
    );

    register_post_type( \'products\', $args );
}
“管理帖子”页面中将显示一个列表框。

结束

相关推荐