I’m writing some code that makes extensive use of custom post types- and I’m looking for a means of programatically adding a category to a defined custom post type, and then accessing its category ID.

I had a poke around but I can’t seem to find a robust means of achieving this – wp_create_category would be the obvious choice but of course this doesn’t support custom post types.

3 s
3

if you need to pre-create some terms you can add the following into the init function that registers the taxonomy. it will create the term foo in the recordings taxonomy

if (!term_exists( 'foo', 'recordings') ){
        wp_insert_term( 'foo', 'recordings' );
    })

Leave a Reply

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