You can use this little plugin for creating taxonomy and custom post types:
<?php
/*
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() {
my_cpt_init();
flush_rewrite_rules();
}
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?
Ivaylo Draganov answers:
Hi,
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="http://codex.wordpress.org/Function_Reference/register_taxonomy_for_object_type"]]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="http://www.wpquestions.com/question/show/id/3005"]]http://www.wpquestions.com/question/show/id/3005[[/LINK]]
[[LINK href="http://wordpress.org/support/topic/bug-taxonomy-terms-multiple-with-same-slug-and-name-in-same-taxonomy"]]http://wordpress.org/support/topic/bug-taxonomy-terms-multiple-with-same-slug-and-name-in-same-taxonomy[[/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..
http://local.dev/tax1/whatever/
http://local.dev/tax2/whatever/
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:
add_term_relationship
added_term_relationship
edit_terms
edited_terms
edit_term_taxonomies
edited_term_taxonomies
delete_term_relationships
deleted_term_relationships
delete_term_taxonomy
deleted_term_taxonomy
Good luck,
Gabriel