Search code examples
phpxmlwordpressfunctionwpallimport

WP All Export for Wordpress: How to use if, elseif condition to get and change attribute data


Is there method to use wp all export php functions to replace data or maybe any other statement we can use directly inside custom XML export.

What i need is to achieve this logic

I have custom taxonomy in XML called {Conditions} which return value of each post as "Used" "New"

Values appear correctly, but where i need to export XML required different values then those above, which i need to replace during export.

Logic:
If {Conditions} = "Used"
Set Used = "20";
Elseif{Conditions} = "New"
Set New = "10";

WP ALL EXPORT PLUGIN


Solution

  • Please take a look at "Pass Data Through PHP Functions" doc:

    "...you can click on the export field and then use the "Export the value returned by a PHP function" option."

    https://www.wpallimport.com/documentation/export/pass-data-through-php-functions/

    You would specify the function name into the text field as in the screenshot on the documentation page (convert_conditions) or, if running a custom XML export, call the function from the field with something like this:

    [convert_conditions({Conditions})]

    ...and provide the function in the function editor for the field:

    function convert_conditions($cond_from_xml = null) {
        if($cond_from_xml === 'Used') {
            return '20';
        } elseif($cond_from_xml === 'New') {
            return '10';
        } else {
            return '0';
        }
    }