Is there a predefined callback function for custom categories?

The callback you’re looking for is post_categories_meta_box which we can use via a custom callback.

// Add your custom meta box.
function your_custom_meta_box() {
  add_meta_box( 'your-custom-meta-box', 'Custom Meta Box', 'my_taxonomy_meta_box_cb', 'post', 'side', 'high', null );
}
add_action( 'add_meta_boxes', 'your_custom_meta_box' );

// Our custom callback.
function my_taxonomy_meta_box_cb( $post, $box ) {

  // Pass in the taxonomy we'd like to use.
  $box[ 'args' ][ 'taxonomy' ] = 'listing_category';

  post_categories_meta_box( $post, $box );
}

Thanks to @birgire for pointing out how not to duplicate code. 🙂

Leave a Comment