• Resolved Aida G

    (@aidadev)


    Hi,

    I need to compare 2 fields before letting the upload to be done. Need to check whether one field values are agreeing before accepting into the database.

    I found this but don’t know how to do this check within this action:

    <?php
    add_action('pmxi_before_xml_import', 'before_xml_import', 10, 1);
    
    function before_xml_import($import_id) {
        echo 'pmxi_before_xml_import';
    }
    
    ?>

    How can I do that please?

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

    (@wpallimport)

    Hi @aidadev

    Here’s an example snippet showing how to access the XML file before the import: https://paste.ee/p/rL9oa.

    Alternatively, if you need to do this on a post-by-post basis, you could use the ‘wp_all_import_is_post_to_create’ hook:

    /**
     * ========================================
     * Filter: wp_all_import_is_post_to_create
     * ========================================
     *
     * Return a boolean indicating if the record should be imported. Note that
     * this is only for new posts. The "wp_all_import_is_post_to_update"
     * filter is for updating existing posts
     *
     * @param $data     array        - An array holding values for the current record. If importing from
     *                                 XML, attributes can be accessed as SimpleXMLElement objects.
     *
     * @return bool (true = create, false = skip)
     */
    function my_is_post_to_create($data)
    {
        // your code here
        return true;
    }
    add_filter('wp_all_import_is_post_to_create', 'my_is_post_to_create', 10, 2);

    We have more info on our hooks (including a link to a github repo with all hooks and more examples) here: https://www.wpallimport.com/documentation/developers/action-reference/.

    Thread Starter Aida G

    (@aidadev)

    Ok. Thanks for the info. But I forgot about “Filtering options” and now using this for comparing one of the column value.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get one of the records value from the uploaded XML/CSV file’ is closed to new replies.