• Resolved frarad

    (@frarad)


    Hello,
    i’m trying to import an XML file with the following structure for attributes:

    <Filter>
    Color>Red|Brand>Lee|Size>42|
    </Filter>

    i’m not used to work with one-line attributes…how can i achieve to separate these and insert them to 3 different attributes (color,brand,size already exists)
    thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @frarad,

    You can use a custom PHP function to fetch the attribute values from that string: https://www.wpallimport.com/documentation/developers/custom-code/inline-php/. Example function:

    function my_get_attr( $attrs = '', $fetch = '' ) {
    	if ( empty( $attrs ) || empty( $fetch ) ) return;
    	$attrs = explode( '|', $attrs );
    	$attrs = array_filter( $attrs );
    	
    	foreach ( $attrs as $att ) {
    		$att = explode( '>', $att );
    		if ( $att[0] == $fetch ) {
    			return $att[1];
    		}
    	}
    }

    Example usage:

    [my_get_attr({Filter[1]},"Color")]
    [my_get_attr({Filter[1]},"Brand")]
    [my_get_attr({Filter[1]},"Size")]
    Plugin Author WP All Import

    (@wpallimport)

    Hi @frarad,

    I’m going to mark this as resolved since it’s been a while. Feel free to follow up here if you still have questions.

    Anyone else with questions, please create a new topic.

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

The topic ‘importing attributes’ is closed to new replies.