Alright, so i have a custom post type called Blurbs (translated, sort of). I want to add a static set of categories for the posts within Blurbs (i don’t want the user to be able to create custom categories). I want two different types of categories; links and page-excerpts. I did some reading and came to the conclusion that taxonomies is the way to go for adding these “categories” to the post type.

I got as far as creating the taxonomy, but i don’t want it visible in the menu. I just want the “category”-box on the edit/publish screen, with the two static items.

This is what i have so far:

$labels = array(
    'name' => 'Categories',
    'singular_name' => 'Category',
    'search_items' => 'Search categories',
    'all_items' => 'All categories',
    'edit_item' => 'Change category',
    'update_item' => 'Update category',
    'add_new_item' => 'Create new category',
    'new_item_name' => 'New category name'
);

register_taxonomy('categories', array('blurb'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
));

By setting the show_ui to false, it disappears from both places (menu and links-box).

So, the two questions i need help with is:

  1. How do i remove it from the menu?
  2. How do i give it “static” options (aka categories) to choose from?

4 s
4

  1. Make it show_ui => false

    Then to show it on the post edit screen add the box manually

    add_action('add_meta_boxes', 'meta_boxes_function');
    
    function meta_boxes_function() {
         add_meta_box('categoriesdiv', 'categories', 'post_categories_meta_box', 'blurb', 'side', null, array('taxonomy' => 'categories'));
    }
    
  2. use this code for every static term

    if(!term_exists('term1', 'categories'))
        wp_insert_term('term1', 'categories');
    

Leave a Reply

Your email address will not be published. Required fields are marked *