I used this class in the tutorial to create two custom post types


According to add_taxonomy() function if the taxonomy already exists then $E2 will be added to that taxonomy. this is achieved by using taxonomy_exists()

if( ! taxonomy_exists( $taxonomy_name ) )
    /* Create taxonomy and attach it to the object type (post type) */
    // register_taxonomy()
    /* The taxonomy already exists. We are going to attach the existing taxonomy to the object type (post type) */
   // register_taxonomy_for_object_type()

here logic is correct but when ever i register a taxonomy for two post_type's only the second post_type will get this taxonomy, first post_type will not be registered with taxonomy

$E1 = new Custom_Post_Type('E1');   
$E2 = new Custom_Post_Type('E2');

$E1->add_taxonomy( 'tax1' );   
$E2->add_taxonomy( 'tax1' );

upon debugging i found out that taxonomy_exists() returns false even when taxonomy is registered.

I tried making $wp_taxonomies global since it holds all taxonomies, but no use.

so problem is with detecting whether a taxonomy is already registered or not.

  • 1
    "that taxonomy_exists() returns false even when taxonomy is registered" how are you confident that it is registered at that poing in execution, when function that exists solely to check that tells you that it's not? – Rarst Mar 27 '14 at 19:10
  • Because i tired to debug it with xDebug and it returned false every time. but taxonomies are registered for last called post_type – Lingaraju Mar 28 '14 at 4:32
  • Could you provide some code for how are you checking that? – Rarst Mar 28 '14 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.