我已经四处寻找了一下,但什么都没有找到(也许我搜索得不够好?)但我试图在从另一个分类法加载的分类法上设置父分类法。
例如,我有汽车品牌和汽车模型,当添加一个新模型时,我想选择它的父级(汽车品牌),而不是它本身的另一个父级。
make不能有任何父级,但可以有无限的子级,模型不能有任何子级,并且父级必须有make。
这可能吗?最好没有插件。
/* Makes */
$labels = array(
\'name\' => _x( \'Makes\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Make\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Makes\' ),
\'all_items\' => __( \'All Makes\' ),
\'parent_item\' => __( \'Parent Make\' ),
\'parent_item_colon\' => __( \'Parent Make:\' ),
\'edit_item\' => __( \'Edit Make\' ),
\'update_item\' => __( \'Update Make\' ),
\'add_new_item\' => __( \'Add New Make\' ),
\'new_item_name\' => __( \'New Make\' ),
);
register_taxonomy(\'makes\', \'car\', array(\'hierarchical\' => false, \'labels\' => $labels, \'query_var\' => false, \'rewrite\' => false, \'with_front\' => false));
/* Models */
$labels = array(
\'name\' => _x( \'Models\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Model\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Models\' ),
\'all_items\' => __( \'All Models\' ),
\'parent_item\' => __( \'Parent Model\' ),
\'parent_item_colon\' => __( \'Parent Model:\' ),
\'edit_item\' => __( \'Edit Model\' ),
\'update_item\' => __( \'Update Model\' ),
\'add_new_item\' => __( \'Add New Model\' ),
\'new_item_name\' => __( \'New Model\' )
);
register_taxonomy(\'models\', \'car\', array(\'hierarchical\' => true, \'labels\' => $labels, \'query_var\' => false, \'rewrite\' => false, \'with_front\' => false));
这个问题有点关联:
Show WordPress Custom Taxonomy Items Based On a Selected Item From Another Custom Taxonomy 然而,我假设父/子元素来自一个分类法?在我的例子中,它们需要是两个独立的分类法。