can I alter imported values during import

Closed
ImportWP Pro - WordPress XML & CSV Importer ImportWP Pro - WordPress XML & CSV Importer August 14, 2020
Login to reply
James Collings Support Agent
3 years ago

Hi Daniel,

An example of how to use the built in filters to update a importer templates field value, please make sure to change the importer id, or commend out that if statement if you do not want to restrict it to a specific importer:

<?php


/**
 * Example code to alter the value of an Importer Templates field
 *
 * @param string $value Field value to insert
 * @param stirng $key Field name
 * @param ImportWP\Common\Model\ImporterModel $importer
 * @return string
 */
function iwpe_alter_field_value_example($value, $key, $importer)
{

    // restrict filter to specific importer (in this case id 47, change to what you need), comment out if not needed
    if ($importer->getId() !== 47) {
        return $value;
    }

    switch ($key) {
        case 'post_date':
            $value = date('Y-m-d H:i:s', strtotime($value));
            break;
    }

    return $value;
}

add_filter('iwp/template/process_field', 'iwpe_alter_field_value_example', 10, 3);

If you need anymore help let me know and i will do my best to help out.

James

Daniel Schmidt
3 years ago

Hi,

I am importing a XML-URL and want to import the post publish date which is formatted for WordPress in a way like: "2020-08-14 10:35:00". The format is provided by the file in a format like "2020-08-14T10:35:00+02:00". Is there a filter hook to alter the inport value with PHP _before_ it is written to the WordPress database?

Maybe it would be great if you could provide a code snippet to include in a functionality plugin or the theme's function.php? I am sure this would provide a great benefit to all the other plugin users.

thank you