4
如何在此功能上使用空格填充深入類別。目前,我有所有類別的選擇框具有相同的級別。類別深度功能
<?php
add_action('add_meta_boxes', 'my_custom_metabox');
function my_custom_metabox() {
add_meta_box('custom-taxonomy-dropdown','Brands','taxonomy_dropdowns_box','post','side','high');
}
function taxonomy_dropdowns_box($post) {
global $brand_taxonomy, $taxonomy_name;
wp_nonce_field('custom-dropdown', 'dropdown-nonce');
$terms = get_terms($brand_taxonomy, 'hide_empty=1&hierarchical=1;');
if (is_a($terms, 'WP_Error')) {
$terms = array();
}
$object_terms = wp_get_object_terms($post->ID, $brand_taxonomy, array('fields'=>'ids'));
if (is_a($object_terms, 'WP_Error')) {
$object_terms = array();
}
// you can move the below java script to admin_head
?>
<?php
wp_dropdown_categories('show_option_none=Select category&show_count=1&hierarchical=1&taxonomy=ad_cat');
echo "Brand:";
echo "<select id='custombrandoptions' name='custombrands[]'>";
echo "<option value='0'>None</option>";
foreach ($terms as $term) {
if (in_array($term->term_id, $object_terms)) {
$parent_id = $term->term_id;
echo "<option value='{$term->term_id}' selected='selected'>{$term->name}</option>";
} else {
echo "<option value='{$term->term_id}'>{$term->name}</option>";
}
}
echo "</select><br />";
echo '<input type="text" value="'.$meta = get_post_meta($post->ID, 'cat_include', true).'" />';
}
來源:http://paste.php.lv/dc485b1e6f37f09f916fccc6ae70ed2f?lang=php
您是否在問如何創建嵌套類別的選擇/選項菜單? – imm
我問,如何從現有的函數數據修復此函數的類別子級別填充。這個功能是advaced wordpress的一部分,帶有下拉框的元框和選擇列表中的自定義分類。 – Foxsk8
這是修復: wp_dropdown_categories('show_count = 1&hierarchical = 1&taxonomy = ad_cat&selected ='。$ meta = get_post_meta($ post-> ID,'cat_include',true)。''); 在選定的參數元框信息上返回。 – Foxsk8