Title: Invalid Taxonomy Error
Last modified: August 21, 2016

---

# Invalid Taxonomy Error

 *  Resolved [davidpetersen](https://wordpress.org/support/users/davidpetersen/)
 * (@davidpetersen)
 * [12 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-1/)
 * Hi!
    First of all, this is an incredible plugin! Thank you for developing it.
   A donation is on its way as soon as I complete this job for this client. I am
   wondering about an error I’ve received.
 * object(WP_Error)#304 (2) { [“errors”]=> array(1) { [“invalid_taxonomy”]=> array(
   1) { [0]=> string(16) “Invalid taxonomy” } } [“error_data”]=> array(0) { } }
 * This is getting thrown when I use the $cpt_onomy->wp_set_object_terms() function.
   I’m calling the function in my functions.php.
 * Any insights as to what might be wrong with this? Thanks for your help!
 * [https://wordpress.org/plugins/cpt-onomies/](https://wordpress.org/plugins/cpt-onomies/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [davidpetersen](https://wordpress.org/support/users/davidpetersen/)
 * (@davidpetersen)
 * [12 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-1/#post-5005262)
 * Looking through the code it seems like it’s not finding the taxonomy that I input.
   Here’s the source:
 * $cpt_onomy->wp_set_object_terms( $meetup_ID , ‘goal-slug-that-user-enters’, ‘
   goals’ , true )
 *  [Rachel Cherry](https://wordpress.org/support/users/bamadesigner/)
 * (@bamadesigner)
 * [12 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-1/#post-5005335)
 * What hook are you using that runs this code? Most likely this code is being run
   before your CPT-onomy is defined.
 *  Thread Starter [davidpetersen](https://wordpress.org/support/users/davidpetersen/)
 * (@davidpetersen)
 * [12 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-1/#post-5005337)
 * Thanks for the response! My functions.php looks like this:
 *     ```
       <?php
       	//Create post types meetups and skills
       	require_once('functions/type-meetups.php');
       	require_once('functions/type-skills.php');
       	require_once('functions/type-skills-profiles.php');
       	require_once("functions/type-messages.php");
       	require_once("functions/type-goals.php");
       	require_once("functions/type-organizations.php");
       	require_once("functions/type-positions.php");
       	require_once("functions/type-schools.php");
       	require_once("functions/type-schools-profiles.php");
   
       	//Allow users to sign-in with email
       	require_once('functions/signin-email.php');
       	require_once('functions/remove-admin-slug.php');
   
       	//Functions to add friends and partnerships
       	require_once("functions/friend-functions.php");
       	require_once("functions/partner-functions.php");
   
       ?>
       ```
   
 * Then the partner-functions.php looks like this:
 *     ```
       <?php
   
       	function add_meetup($sender_ID, $recipient_ID, $pitch, $goal, $skill, $meetup_date){
   
       		//echo $sender_ID."<br><br>". $recipient_ID."<br><br>".$pitch."<br><br>". $goal."<br><br>".$skill."<br><br>". $meetup_date;
   
       		$sender = get_userdata(intval($sender_ID));
       		$recipient = get_userdata(intval($recipient_ID));
   
       		$meetup = array(
       		  'post_title'    => "Meetup between $sender->first_name $sender->last_name and $recipient->first_name $recipient->last_name",
       		  'post_content'  => $pitch,
       		  'post_status'   => 'publish',
       		  'post_type'	  => 'meetups',
       		  'comment_status' => 'open',
       		);
   
       		$meetup_ID = wp_insert_post( $meetup );
   
       		global $cpt_onomy;
       		$cpt_onomy->wp_set_object_terms(  $meetup_ID , 'stars', 'goals' , true );
       		add_post_meta($meetup_ID, 'possible_dates', $meetup_date);
       		add_post_meta($meetup_ID, 'sender', $sender_ID);
       		add_post_meta($meetup_ID, 'recipient', $recipient_ID);
   
       		exit();
       		wp_redirect('http://www.wisevice.com/meetups/'.get_post( $meetup_ID )->post_name);
       	}
   
       	if ($_POST["sender_ID"] && $_POST["recipient_ID"] && $_POST["add_partnership"]){
   
       		add_meetup($_POST["sender_ID"],$_POST["recipient_ID"], $_POST["pitch"], $_POST["goal"], $_POST["skill"], $_POST["meetup_date"]); 
   
       	}
   
       	if(isset($_GET["confirm"]) && isset($_GET["confirm_ID"])){
       			update_post_meta($_GET["confirm_ID"], 'confirmed_date' , $_GET["confirm"]);
       			wp_publish_post( $_GET["confirm_ID"] ) ;
       		}
       ?>
       ```
   
 * It’s just called when the page loads, but I’m not using a hook. I’ve tried including
   the partner-functions.php in functions.php using the wp_loaded hook and it did
   change the error message. The function just returned a blank array.
 *  [Rachel Cherry](https://wordpress.org/support/users/bamadesigner/)
 * (@bamadesigner)
 * [12 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-1/#post-5005340)
 * You’re going to have to use a hook in order to access your CPT-onomy because 
   they’re not defined until the ‘init’ hook runs. I recommend using the ‘wp_loaded’
   action to access your CPT-onomy.
 *  Thread Starter [davidpetersen](https://wordpress.org/support/users/davidpetersen/)
 * (@davidpetersen)
 * [12 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-1/#post-5005377)
 * Thanks for the help! Now I’ve created a hook for the wp_loaded action and it’s
   just giving a blank array.
 * Here’s the hook code
 *     ```
       <?php
   
       add_action('wp_loaded','addpart');
       function addpart(){
       	if ($_POST["sender_ID"] && $_POST["recipient_ID"] && $_POST["add_partnership"]){
   
       		$sender_ID = $_POST["sender_ID"];
       		$recipient_ID = $_POST["recipient_ID"];
       		$pitch= $_POST["pitch"];
       		$goal= $_POST["goal"];
       		$skill = $_POST["skill"];
       		$meetup_date = $_POST["meetup_date"];
   
       		//echo $sender_ID."<br><br>". $recipient_ID."<br><br>".$pitch."<br><br>". $goal."<br><br>".$skill."<br><br>". $meetup_date;
   
       		$sender = get_userdata(intval($sender_ID));
       		$recipient = get_userdata(intval($recipient_ID));
   
       		$meetup = array(
       		  'post_title'    => "Meetup between $sender->first_name $sender->last_name and $recipient->first_name $recipient->last_name",
       		  'post_content'  => $pitch,
       		  'post_status'   => 'publish',
       		  'post_type'	  => 'meetups',
       		  'comment_status' => 'open',
       		);
   
       		$meetup_ID = wp_insert_post( $meetup );
   
       		global $cpt_onomy;
   
       		print_r($cpt_onomy->wp_set_object_terms(  $meetup_ID , 'stars', 'goals' , true ));
       		add_post_meta($meetup_ID, 'possible_dates', $meetup_date);
       		add_post_meta($meetup_ID, 'sender', $sender_ID);
       		add_post_meta($meetup_ID, 'recipient', $recipient_ID);
   
       		wp_redirect('http://www.wisevice.com/meetups/'.get_post( $meetup_ID )->post_name);
   
       	}
       }
       ?>
       ```
   
 * If I var_dump the $cpt_onomy variable I get this : object(CPT_TAXONOMY), which
   makes me think that it IS registered and accessible. This is working on every
   other page I need it to. It’s just this page that’s a problem. This code is on
   the search page. Could that change anything?
 *  Thread Starter [davidpetersen](https://wordpress.org/support/users/davidpetersen/)
 * (@davidpetersen)
 * [12 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-1/#post-5005378)
 * I think the problem is solved. For some reason using the intval of the meetup_ID
   made it work. Any clue why?
 *  Thread Starter [davidpetersen](https://wordpress.org/support/users/davidpetersen/)
 * (@davidpetersen)
 * [12 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-1/#post-5005379)
 * Actually I think it was the hook thing. Thanks for the help though! You’re great.
 *  [Rachel Cherry](https://wordpress.org/support/users/bamadesigner/)
 * (@bamadesigner)
 * [12 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-1/#post-5005411)
 * Hooray! No problem. 🙂

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Invalid Taxonomy Error’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/cpt-onomies_f2f2f2.svg)
 * [CPT-onomies: Using Custom Post Types as Taxonomies](https://wordpress.org/plugins/cpt-onomies/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cpt-onomies/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cpt-onomies/)
 * [Active Topics](https://wordpress.org/support/plugin/cpt-onomies/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cpt-onomies/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cpt-onomies/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [Rachel Cherry](https://wordpress.org/support/users/bamadesigner/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-1/#post-5005411)
 * Status: resolved