• Resolved bobdesign

    (@bobdesign)


    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

    (@wpallimport)

    Hi @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/. 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

    (@wpallimport)

    Hi @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.