例如,我有主要的文章写在默认的wordpress文章,现在我有自定义的post类型叫做能量,在这里我想添加主文章作为这个能源CPT的父。
Wordpress posts =家长能源CPT =子女
请帮我处理密码。
再举一个例子:我想把能源帖子10(作为子)和wordpress的主帖子20(作为家长)联系起来。
我有100's的帖子,所以请帮忙。
发布于 2022-01-19 23:28:25
通常,父级子关系是使用页类型完成的。请看我附上的图片的右边,上面写着“家长”。在单个post类型中,您还可以使用我认为的父级子类别。可能有两种post类型,您可以使用一个分类法,也可以使用父子类别。通常不推荐。否则,我猜您必须设置一个meta字段并存储父ID。
通常,没有多个posts类型的性能增益,它们存储在同一个"wp_posts“表中。通常使用多个post类型,如筒仓,独立使用。
这里是一个自定义的层次化的post类型,它的行为将像一个页面。
add_action( 'init', 'create_chapter_post_type' );
function create_chapter_post_type() {
register_post_type( 'chapters',
array(
'labels' => array(
'name' => __( 'Chapters' ),
'singular_name' => __( 'Chapter' ),
'add_new' => 'Add New Chapter',
'add_new_item' => 'Add New Chapter'
),
'public' => true,
'hierarchical' => true,
'supports' => array('title', 'editor', 'page-attributes', 'custom-fields')
)
);
}
同样,默认情况下,页面支持父级子关系。
https://wordpress.stackexchange.com/questions/401522
复制相似问题