WordPress.org

Forums

[resolved] WP All Import - create multiple file path with [FOREACH] (2 posts)

  1. Schmalitz
    Member
    Posted 1 year ago #

    I need to solve following obstacle to create variable file-path:

    The FOREACH shortcode returns a specific XML-field like this:

    [FOREACH({Filename})]
    {.}
    [ENDFOREACH]<br>

    Resulting in

    Filename 1
    Filename 2
    Filename 3
    etc.

    That's fine but I need to do this:

    fix/{CAT[1]}/Filename 1
    fix/{CAT[1]}/Filename 2
    fix/{CAT[1]}/Filename 3
    etc.

    ...where {CAT[1]} is a variable output of the XML.

    Any ideas?

    Thank you very much for your help in advance!

  2. Schmalitz
    Member
    Posted 1 year ago #

    I also asked the official support (Soflyy) the same question and got the answer.

    Code for the functions.php:

    global $upc;
    
    function set_upc($local_upc){
    global $upc;
    $upc = $local_upc;
    }
    
    function myfunc($files){
    global $upc;
    return $upc . '/' . $files;
    }

    Code for the import template:

    [set_upc({UPC[1]})]
    [FOREACH({Tracks[1]/Track})]
    <a href=>[myfunc({AudioFiles[1]/AudioFile[1]/Filename[1]})]
    [ENDFOREACH]

    Now its very easy to play around with the tempalte code to change the anchor text, structur etc.

    Thanks to Soflyy! Excellent support!

Topic Closed

This topic has been closed to new replies.

About this Topic