Documentation / Code Snippets

How to change an importers unique identifier

Each importer uses a specific list of fields and fallback fields to identify each item being imported, the following filter allows you to alter this and return a list of unique identifier fields, such as default post, taxonomy and user fields, or custom fields.

use ImportWP\Common\Importer\TemplateInterface;
use ImportWP\Common\Model\ImporterModel;

add_filter('iwp/template_unique_fields', function($unique_fields, TemplateInterface $template, ImporterModel $importer_model){

    // return an array of unique fields to check, 
    // _custom_field_1 will be used by default, 
    // and the post_name will be used as a fallback field.

    return ['_custom_field_1', 'post_name'];

}, 10, 3);