Title: categoryID function for value
Last modified: April 27, 2019

---

# categoryID function for value

 *  Resolved [bobdesign](https://wordpress.org/support/users/bobdesign/)
 * (@bobdesign)
 * [7 years ago](https://wordpress.org/support/topic/categoryid-function-for-value/)
 * Hey,
    i need some help with my XML import.
 * i have import the Categories with names and a custom field vor CatID (for ex.
   1234)
 * Now when i want to import the products, i only get the id´s of categories and
   not the name.
    So the import will add new cats with the id´s.
 * i have seen the “mapping function” which is built in wp all import, but i have
   more than 200 different categories and ids.
 * Is there any solution for an php function, to check the id in the term “CatID”
   and set the value?
 * thats what i have in import
    <category>2399,2400,2655</category>
 * cat 2399 = Parent category A
    cat 2400 = Child category A . . .
 * Would be great if you have a solution for me.
 * Cheers

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

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [7 years ago](https://wordpress.org/support/topic/categoryid-function-for-value/#post-11490329)
 * Hi [@bobdesign](https://wordpress.org/support/users/bobdesign/)
 * > Is there any solution for an php function, to check the id in the term “CatID”
   > and set the value?
 * Yes, you can use a custom PHP function for this: [http://www.wpallimport.com/documentation/developers/execute-php/](http://www.wpallimport.com/documentation/developers/execute-php/).
   Here is an example that you can adjust as needed:
 *     ```
       function my_get_category( $ids ) {
       	if ( ! empty( $ids ) ) {
       		$return = array();
       		$ids = explode( ",", $ids );
       		foreach ( $ids as $id ) {
       			$id = trim( $id );
       			$term = get_terms( array(
       				'taxonomy' => 'product_cat',
       				'hide_empty' => false,
       				'meta_query' => array(
       					'key' => '_category_id',
       					'value' => $id,
       					'compare' => '='
       				)
       			) );
       			if ( ! empty( $term ) ) {
       				$return[] = $term[0]->slug;
       			}	
       		}
       		if ( ! empty( $return ) ) {
       			return implode( ">", $return );
       		}
       	}	
       }
       ```
   
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [7 years ago](https://wordpress.org/support/topic/categoryid-function-for-value/#post-11514935)
 * Hi [@bobdesign](https://wordpress.org/support/users/bobdesign/)
 * I’m marking the thread as resolved. Let me know if you have more questions about
   this. Anyone else, please open a new thread.

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

The topic ‘categoryID function for value’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-import/assets/icon-256x256.png?rev=2570179)
 * [WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets](https://wordpress.org/plugins/wp-all-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-import/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-import/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [7 years ago](https://wordpress.org/support/topic/categoryid-function-for-value/#post-11514935)
 * Status: resolved