我正在创建一个“葡萄酒数据库”,称之为“葡萄酒数据库”。。。。基本上,有一个定制的帖子类型叫做“葡萄酒”,然后它有葡萄酒、葡萄色等属性。。。。。还有“地区”和“生产者”。我创建了最后两个自定义帖子类型,因为用户需要能够通过仪表板创建“producer”和“region”页面/帖子,基本上,他们需要的元素与创建新帖子时相同。
我不允许使用任何插件(付费或非付费)或任何主题,因此我必须对所有内容进行硬编码。
事实是。。。。我曾尝试将它们创建为分类法,但后来我无法确定如何通过仪表板添加帖子或页面的所有功能,因为它只包含标题、slug和描述。。。
好吧,现在我的问题是,我已经创建了带有下拉列表的元框,所以当您创建新葡萄酒时,您可以在元框中选择区域和生产者。问题它只保存生产者:S一旦我选择了区域,并尝试更新,所选选项将再次变为未选中。
有什么关于为什么会这样的建议吗?如果wp\\u dropdown\\u页面出现问题,因为这是唯一让我觉得可能是错误的东西。。。。有没有其他建议?
非常感谢。
因此,我在这里注册了我的自定义帖子类型:
add_action(\'init\', function(){
$labels = array(
"name" => "Producers",
"singular_name" => "Producer",
"menu_name" => "Producers",
"all_items" => "All Producers",
"add_new" => "Add New",
"add_new_item" => "Add New Producers",
"edit" => "Edit",
"edit_item" => "Edit Producer",
"new_item" => "New Producer",
"view" => "View",
"view_item" => "View Producer",
"search_items" => "Search Producers",
"not_found" => "No Producers Found",
"not_found_in_trash" => "No Producers Found in Trash",
"parent" => "Parent Producers",
);
$args = array(
"labels" => $labels,
"description" => "",
"public" => true,
"show_ui" => true,
"has_archive" => true,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => true,
"rewrite" => array( "slug" => "producers", "with_front" => true ),
"query_var" => true,
"supports" => array(
"editor",
"title",
"thumbnail",
"revisions",
"custom-fields",
"page-attributes",
)
);
register_post_type( "producer", $args );
$labels = array(
"name" => "Wines",
"singular_name" => "Wine",
);
$args = array(
"labels" => $labels,
"description" => "",
"public" => true,
"show_ui" => true,
"has_archive" => true,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array( "slug" => "wines", "with_front" => true ),
"query_var" => true,
"supports" => array(
"editor",
"title",
"thumbnail",
"revisions",
"custom-fields",
"page-attributes",
),
);
register_post_type( "wines", $args );
$labels = array(
"name" => "Regions",
"singular_name" => "Region",
"menu_name" => "Regions",
"all_items" => "All Regions",
"add_new" => "Add New",
"add_new_item" => "Add Region",
"edit" => "Edit",
"edit_item" => "Edit Region",
"new_item" => "Region",
"view" => "View",
"view_item" => "View Region",
"search_items" => "Search Regions",
"not_found" => "No Region Found",
"not_found_in_trash" => "No Region Found in Trash",
"parent" => "Parent Country",
);
$args = array(
"labels" => $labels,
"description" => "",
"public" => true,
"show_ui" => true,
"has_archive" => true,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => true,
"rewrite" => array( "slug" => "regions", "with_front" => true ),
"query_var" => true,
"supports" => array(
"editor",
"title",
"thumbnail",
"revisions",
"custom-fields",
"page-attributes",
)
);
register_post_type( "region", $args );
});
在这里,我使用下拉列表注册元框:
add_action(\'add_meta_boxes\', function() {
add_meta_box(\'wines2-parent\', \'regions\', \'wines_attributes_meta_box2\', \'wines\', \'side\', \'default\');
});
function wines_attributes_meta_box2($post) {
$pages = wp_dropdown_pages(array(\'post_type\' => \'region\', \'selected\' => $post->post_parent, \'name\' => \'parent_id\', \'show_option_none\' => __(\'(no parent)\'), \'sort_column\'=> \'menu_order, post_title\', \'echo\' => 0));
if ( ! empty($pages) ) {
echo $pages;
} // end empty pages check
}
add_action(\'add_meta_boxes\', function() {
add_meta_box(\'wines-parent\', \'producers\', \'wines_attributes_meta_box\', \'wines\', \'side\', \'default\');
});
function wines_attributes_meta_box($post) {
$pages = wp_dropdown_pages(array(\'post_type\' => \'producer\', \'selected\' => $post->post_parent, \'name\' => \'parent_id\', \'show_option_none\' => __(\'(no parent)\'), \'sort_column\'=> \'menu_order, post_title\', \'echo\' => 0));
if ( ! empty($pages) ) {
echo $pages;
} // end empty pages check
}