Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

taxonomy sync action for adding/editing/deleting WordPress


You can use this little plugin for creating taxonomy and custom post types:

Plugin Name: CPT
function my_cpt_init() {
register_post_type('product1', array( 'label' => 'product1' , 'public' => true ) );
register_post_type('product2', array( 'label' => 'product2' , 'public' => true ) );
register_post_type('product3', array( 'label' => 'product3' , 'public' => true ) );
register_post_type('product4', array( 'label' => 'product4' , 'public' => true ) );

register_taxonomy('tax1','product1',array('label' => 'tax1' , 'hierarchical' => true, 'slug' => 'product1/tax1'));
register_taxonomy('tax2','product2',array('label' => 'tax2' , 'hierarchical' => true, 'slug' => 'product2/tax2'));
register_taxonomy('tax3','product3',array('label' => 'tax3' , 'hierarchical' => true, 'slug' => 'product3/tax3'));
register_taxonomy('tax4','product4',array('label' => 'tax4' , 'hierarchical' => true, 'slug' => 'product4/tax4'));
add_action('init', 'my_cpt_init');

function my_rewrite_flush() {
register_activation_hook(__FILE__, 'my_rewrite_flush');

I need to have 4 different taxonomy for 4 different custom post type but those taxonomies need to have same terms inside. So when someone adding a term, editing a term or deleting a term on any of those taxonomies, other taxonomies need to get same changes too.. Term id's not need to be same but names and child/parent relations need to be same.

Whats proper solution for it?

Answers (2)


Ivaylo Draganov answers:


I don't think that you need 4 separate taxonomies - you should just use one and attach it to the different post types. That way you don't need to worry about syncing.

Use the function:

register_taxonomy_for_object_type( 'taxonomy', 'post_type' );

Check out [[LINK href=""]]the Codex for more info[[/LINK]].

Ünsal Korkmaz comments:

dude its a bit long story. believe me i need 4 different taxonomy.

Ivaylo Draganov comments:

Well, it could be made but bear in mind that term slugs might have to be different. And that generally this is a lot of trouble. Read some stuff on the topic:
[[LINK href=""]][[/LINK]]
[[LINK href=""]][[/LINK]]

Ünsal Korkmaz comments:

i just tried to add taxonomy with same name in tax1 and tax2 on this example, i didnt get any error or something..

Ivaylo Draganov comments:

<blockquote>i just tried to add taxonomy with same name in tax1 and tax2 on this example, i didnt get any error or something.. </blockquote>
Yes, I said they <em>might </em>have to be different.

Gabriel Reguly has pointed you to the hooks to use and I share his opinion that $10 is not enough for such a task.


Gabriel Reguly answers:

Hi Ünsal Korkmaz,

$10 is not enough for custom code, but I'll list some actions for you to hook the needed functions:






Good luck,