Title: Invalid taxonomy error when using taxonomy fields
Last modified: August 31, 2016

---

# Invalid taxonomy error when using taxonomy fields

 *  Resolved [zpanda](https://wordpress.org/support/users/zpanda/)
 * (@zpanda)
 * [10 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-when-using-taxonomy-fields/)
 * Hi, I’m trying use a radio taxonomy field and I keep getting the error below.
 * _Notice: Trying to get property of non-object in /srv/www/oc.com/current/web/
   app/mu-plugins/cmb2/includes/CMB2\_Types.php on line 703_
 * print_r($terms) error msg:
    _WP\_Error Object ( [errors] => Array ( [invalid\
   _taxonomy] => Array ( [0] => Invalid taxonomy ) ) [error\_data] => Array ( ) )_
 * I have two custom taxonomies set up and am able to access them via admin..so 
   I believe they are valid.
 * I’ve tried the custom taxonomy slugs with the other taxonomy fields and keep 
   receiving the same error. ‘categories’ or ‘post_tag’ slugs work.
 * Here is my code for taxonomies and what I have for the fields.
 *     ```
       // Register Custom Taxonomy
       function oc_listing_type_taxonomy() {
   
       	$labels = array(
       		'name'                       => _x( 'Rent Listing Type', 'Taxonomy General Name', 'text_domain' ),
       		'singular_name'              => _x( 'Rent Listing Type', 'Taxonomy Singular Name', 'text_domain' ),
       		'menu_name'                  => __( 'For Rent', 'text_domain' ),
       		'all_items'                  => __( 'For Rent', 'text_domain' ),
       		'parent_item'                => __( 'Parent Genre', 'text_domain' ),
       		'parent_item_colon'          => __( 'Parent Genre:', 'text_domain' ),
       		'new_item_name'              => __( 'For Rent', 'text_domain' ),
       		'add_new_item'               => __( 'Add For Rent', 'text_domain' ),
       		'edit_item'                  => __( 'Edit For Rent', 'text_domain' ),
       		'update_item'                => __( 'Update For Rent', 'text_domain' ),
       		'view_item'                  => __( 'View Item', 'text_domain' ),
       		'separate_items_with_commas' => __( 'Separate genres with commas', 'text_domain' ),
       		'add_or_remove_items'        => __( 'Add or remove genres', 'text_domain' ),
       		'choose_from_most_used'      => __( 'Choose from the most used genres', 'text_domain' ),
       		'popular_items'              => __( 'Popular Items', 'text_domain' ),
       		'search_items'               => __( 'Search For Rent', 'text_domain' ),
       		'not_found'                  => __( 'Not Found', 'text_domain' ),
       		'no_terms'                   => __( 'No items', 'text_domain' ),
       		'items_list'                 => __( 'Items list', 'text_domain' ),
       		'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
       	);
       	$rewrite = array(
       		'slug'                       => 'for_rrent',
       		'with_front'                 => true,
       		'hierarchical'               => true,
       	);
       	$args = array(
       		'labels'                     => $labels,
       		'hierarchical'               => true,
       		'public'                     => true,
       		'show_ui'                    => true,
       		'show_admin_column'          => true,
       		'show_in_nav_menus'          => true,
       		'show_tagcloud'              => false,
       		'rewrite'                    => $rewrite,
       	);
       	register_taxonomy( 'oc_rent_listing_type', array( 'listings' ), $args );
   
       	// Register For Sale Taxonomy
       	$labels = array(
       		'name'                       => _x( 'Sale Listing Type', 'Taxonomy General Name', 'text_domain' ),
       		'singular_name'              => _x( 'Sale Listing Type', 'Taxonomy Singular Name', 'text_domain' ),
       		'menu_name'                  => __( 'For Sale', 'text_domain' ),
       		'all_items'                  => __( 'For Sale', 'text_domain' ),
       		'pasale_item'                => __( 'Pasale Genre', 'text_domain' ),
       		'pasale_item_colon'          => __( 'Pasale Genre:', 'text_domain' ),
       		'new_item_name'              => __( 'For Sale', 'text_domain' ),
       		'add_new_item'               => __( 'Add For Sale', 'text_domain' ),
       		'edit_item'                  => __( 'Edit For Sale', 'text_domain' ),
       		'update_item'                => __( 'Update For Sale', 'text_domain' ),
       		'view_item'                  => __( 'View Item', 'text_domain' ),
       		'separate_items_with_commas' => __( 'Separate genres with commas', 'text_domain' ),
       		'add_or_remove_items'        => __( 'Add or remove genres', 'text_domain' ),
       		'choose_from_most_used'      => __( 'Choose from the most used genres', 'text_domain' ),
       		'popular_items'              => __( 'Popular Items', 'text_domain' ),
       		'search_items'               => __( 'Search For Sale', 'text_domain' ),
       		'not_found'                  => __( 'Not Found', 'text_domain' ),
       		'no_terms'                   => __( 'No items', 'text_domain' ),
       		'items_list'                 => __( 'Items list', 'text_domain' ),
       		'items_list_navigation'      => __( 'Items list navigation', 'text_domain' ),
       	);
       	$rewrite = array(
       		'slug'                       => 'for_sale',
       		'with_front'                 => true,
       		'hierarchical'               => true,
       	);
       	$args = array(
       		'labels'                     => $labels,
       		'hierarchical'               => true,
       		'public'                     => true,
       		'show_ui'                    => true,
       		'show_admin_column'          => true,
       		'show_in_nav_menus'          => true,
       		'show_tagcloud'              => false,
       		'rewrite'                    => $rewrite,
       	);
       	register_taxonomy( 'oc_sale_listing_type', array( 'listings' ), $args );
       }
       add_action( 'init', 'oc_listing_type_taxonomy', 0 );
       ```
   
 *     ```
       $cmb->add_field( array(
       	    'name'     => 'Test Taxonomy Select',
       	    'desc'     => 'Description Goes Here',
       	    'id'       => 'wiki_test_taxonomy_select',
       	    'taxonomy' => 'for_rrent', //Enter Taxonomy Slug
       	    'type'     => 'taxonomy_select',
       	) );
       ```
   
 * [https://wordpress.org/plugins/cmb2/](https://wordpress.org/plugins/cmb2/)

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

 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [10 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-when-using-taxonomy-fields/#post-7449362)
 * Based on your code, the taxonomy id is `'oc_rent_listing_type'`, not ‘`for_rrent`‘.
 * It needs to be the first argument to `register_taxonomy`.
 *  Thread Starter [zpanda](https://wordpress.org/support/users/zpanda/)
 * (@zpanda)
 * [10 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-when-using-taxonomy-fields/#post-7449364)
 * Oh. Thank you! The example has //Enter Taxonomy Slug next to it in the comments
   so I became stuck on that. So how do I actually reference for_rrent and for_sale?
   Those have children taxonomy created which I want to appear.
 *  Thread Starter [zpanda](https://wordpress.org/support/users/zpanda/)
 * (@zpanda)
 * [10 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-when-using-taxonomy-fields/#post-7449380)
 * oh nevermind, I figured it out. Thank you.

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

The topic ‘Invalid taxonomy error when using taxonomy fields’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

## Tags

 * [taxonomy](https://wordpress.org/support/topic-tag/taxonomy/)

 * 3 replies
 * 2 participants
 * Last reply from: [zpanda](https://wordpress.org/support/users/zpanda/)
 * Last activity: [10 years ago](https://wordpress.org/support/topic/invalid-taxonomy-error-when-using-taxonomy-fields/#post-7449380)
 * Status: resolved