0

I'm using Divi with a child theme. Divi (parent theme) has a CPT called project and two custom taxonomies, project_category and project_tag.

In my child theme I created a CPT called external_project. I want this newly created CPT to share the same taxonomies that the built-in Projects post type has. When registering this CPT I added 'taxonomies' => array( 'project_category', 'project_tag' ), to the args. But they're not showing up. So I'm assuming I also need to add this newly created CPT to the array of object types the custom taxonomy is associated with.

I tried the following. I didn't think it would work but I just wanted to try something, and of course it didn't work. So don't judge me too hard for it lol

function add_cpt_to_project_tax() {
    register_taxonomy('project_category', array('project', 'external_project'));
    register_taxonomy('project_tag', array('project', 'external_project'));
}
add_action('after_setup_theme', 'add_cpt_to_project_tax');

So my question is...Does anyone know of a hook or function I can create that will add the newly created CPT in my child theme, to the custom taxonomy registered in the parent theme? I'm having a tough time finding any examples online or anything in the codex that will help with my specific scenario. Any help would be greatly appreciated.

1 Answer 1

0

Ok, so after another hours of digging through the codex, I found a solution. Hope this helps anyone else who is runs into the same issue. I had to use the register_taxonomy_for_object_type function. And then I used the init hook. Here is the function that worked for me.

function add_cpt_to_project_tax(){
    register_taxonomy_for_object_type('project_category', 'external_project');
    register_taxonomy_for_object_type('project_tag', 'external_project');
}
add_action('init','add_cpt_to_project_tax');

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.