I have a custom post I am looking to categorize via a custom taxonomy. The taxonomy itself I want to be dependent on the items of another custom post type. Is it possible to populate a taxonomy via the items of a custom post type, or is it something I have to do manually?

Plugins, snippets, guidance on alternat methods of approach would be greatly appreciated.

EDIT WITH EXAMPLE:

I have a custom post type that basically acts like a page. When I create one, I want it to populate a custom taxonomy with its title. Daniel Dvorkin’s answer is the sort of solution I was thinking about.

3 Answers
3

I always use something like:

add_action('save_post', 'mdz_correlate_casos_taxonomy');
function mdz_correlate_casos_taxonomy( $post_id ){

    if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
        return $post_id;

    if ( 'YOUR CUSTOM POST TYPE' == $_POST['post_type'] ){
        if (!wp_is_post_revision($post_id)){
            if (!term_exists( $_POST["post_title"], 'YOUR CUSTOM TAXONOMY' )){

                $termid = wp_insert_term( $_POST["post_title"], 'YOUR CUSTOM TAXONOMY' );

            }
        }
    }

}

But this is prone to get inconsistent (ie: if you delete a post, the term won’t get deleted)

Leave a Reply

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