WordPress – Adding a post category box to custom post type

I have created a custom post type called ‘Case Studies’ … What i want to be able to do is display the box with the categories of normal posts inside the Case Studies ‘add case study page’, so i can choose posts that are associated with the case study im making.

All this done in the admin section.

Read More

Any suggestions would be great.

Cheers,

Related posts

Leave a Reply

3 comments

  1. In your register_post_type function’s arguments array parameter, add the following key and array value to add the regular categories in the custom post type add/edit page:

    'taxonomies' => array("category")

    For example:

    register_post_type( 'slider',
        array(
            'labels' => array(
            'name' => _x( 'Slider', 'post type general name' ),
            'singular_name' => _x( 'Slider', 'post type singular name' ),
            'add_new' => _x( 'Add New', 'Slider' ),
            'add_new_item' => __( 'Add New Slider' ),
            'edit_item' => __( 'Edit Slider' ),
            'new_item' => __( 'New Slider' ),
            'view_item' => __( 'View Slider' ),
            'search_items' => __( 'Search Slider' ),
            'not_found' =>  __( 'No Slider Items found' ),
            'not_found_in_trash' => __( 'No Slider Items found in Trash' ),
            'parent_item_colon' => ''
        ),
            'public' => true,
            'exclude_from_search' => true,
            'show_in_nav_menus' => false,
            'supports' => array('title','thumbnail'),
            'taxonomies' => array("category"),   /* This is what you are looking for and the value has to be an array. */
            'rewrite' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'menu_position' => null,
        )
    );
    

    For details see the WordPress register_post_type function documentation.

  2. try this or check this tutorial

    function Book() {
      $labels = array(
        'name'               => 'Books',
        'singular_name'      => 'Book',
        'add_new'            => 'Add New',
        'add_new_item'       => 'Add New Book',
        'edit_item'          => 'Edit Book',
        'new_item'           => 'New Book',
        'all_items'          => 'All Books',
        'view_item'          => 'View Book',
        'search_items'       => 'Search Books',
        'not_found'          => 'No books found',
        'not_found_in_trash' => 'No books found in Trash',
        'parent_item_colon'  => '',
        'menu_name'          => 'Books'
      );
    
      $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'book' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
        'taxonomies' => array('category', 'post_tag')
      );
    
      register_post_type( 'book', $args );
    }
    add_action( 'init', 'book' );
    
  3. Ohh, interesting. Not that i have done this before but i just thinking of it makes it exciting. I do things a little dirty so forgive me.

    I would a special tag to my custom post. Then add a second loop to my custom post that would query posts based on that tag.