4

I'm using some custom posts types, and, I don't wanna create specific categories for each one.

I'd like to use the Post Category in all my Custom Post.

Here is a example of my new custom posts type:

I know how create new category type for my custom posts, but I don't know how use the regular categories from posts.

/*  New Custom Post - Cupons
/* ------------------------------------ */

add_action( 'init', 'create_post_type_cupons' );
function create_post_type_cupons() {
    register_post_type( 'cupom',
        array(
            'labels' => array(
                'name' => __( 'Cupons' ),
                'singular_name' => __( 'Cupom' )
            ),
            'public' => true,
        )
    );
}
6

The documentation for register_post_type mentions a taxonomies parameter, giving it a value of array( 'category' ) will do what you want.

There is also the register_taxonomy_for_object_type function

1

After

'public' => true,

you add

'taxonomies' => array('category','post_tag'),

this one create category and tag for your custom post type if you want just category the delete ,'post_tag'.

1

I added the function register_taxonomy_for_object_type( $taxonomy, $object_type ) in functions.php.

First: I need to choose which kind of taxonomy I want, in this case, "category".

Second: I choose the object type, in this case, "cupom" that is my Custom Post Type.

add_action('init','add_categories_to_cupom');
function add_categories_to_cupom(){
    register_taxonomy_for_object_type('category', 'cupom');
}

So now, my Custom Post Type "cupom" uses the the Posts Category.

  • Please expand upon this answer by including an explanation of the code. (Also, there is no "above". The stack supports mupliple ways to sort answers) – s_ha_dum May 26 '15 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.