自wp 3.8以来,您可以通过meta_box_cb
“drop\\u cat()”-由重建原始核心类别metaboxwp admin/includes/meta框组成。php
function realty_type() {
$args = array(
\'show_ui\' => true,
\'meta_box_cb\' => \'drop_cat\',
);
register_taxonomy( \'realty_type\', array( \'YOUR_POST_TYPE\' ), $args );
}
// Hook into the \'init\' action
add_action( \'init\', \'realty_type\', 0 );
function drop_cat( $post, $box ) {
$defaults = array(\'taxonomy\' => \'category\');
if ( !isset($box[\'args\']) || !is_array($box[\'args\']) )
$args = array();
else
$args = $box[\'args\'];
extract( wp_parse_args($args, $defaults), EXTR_SKIP );
$tax = get_taxonomy($taxonomy);
?>
<div id="taxonomy-<?php echo $taxonomy; ?>" class="acf-taxonomy-field categorydiv">
<?php
$name = ( $taxonomy == \'category\' ) ? \'post_category\' : \'tax_input[\' . $taxonomy . \']\';
echo "<input type=\'hidden\' name=\'{$name}[]\' value=\'0\' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
?>
<? $term_obj = wp_get_object_terms($post->ID, $taxonomy ); //_log($term_obj[0]->term_id)?>
<ul id="<?php echo $taxonomy; ?>checklist" data-wp-lists="list:<?php echo $taxonomy?>" class="categorychecklist form-no-clear">
<?php //wp_terms_checklist($post->ID, array( \'taxonomy\' => $taxonomy) ) ?>
</ul>
<?php wp_dropdown_categories( array( \'taxonomy\' => $taxonomy, \'hide_empty\' => 0, \'name\' => "{$name}[]", \'selected\' => $term_obj[0]->term_id, \'orderby\' => \'name\', \'hierarchical\' => 0, \'show_option_none\' => \'—\' ) ); ?>
</div>
<?php
}