I would like to "update" existing content (posts/pages/woocommerce products). How can I run an "update" import?

Closed
ImportWP Pro - WordPress XML & CSV Importer ImportWP Pro - WordPress XML & CSV Importer July 11, 2019
Login to reply
James Grimes
2 weeks ago

Has this issue been resolved? I'm running into the same problem. Could you post the fix here please?

Thanks.

James Collings Support Agent
2 months ago

The "Not enough permission to insert record", is because you only want to update existing records, and it cant find an existing record (because we only gave it the update pemission via Import Settings > Permissions).

Was that for every record?

Brian Potter
2 months ago

Gotcha. Ok. I ran the import with the new snippet. I got this error:

Error: No Enough Permissions to Insert Record

Is this something I need to talk to the host about?

James Collings Support Agent
2 months ago

Hi,

Your function looks correct for only importing those two custom fields.

The main settings for your importer should be:

Import Settings > General

unique field: ID

Import Settings > Permissions

make sure update is the only one checked

Template Fields Post/Page > Settings

Enable ID Field

Template Fields Post/Page > Fields

Set value for ID field from xml or CSV file


Yes you should setup references to the values from the csv file for both 

_yoast_wpseo_opengraph and _yoast_wpseo_metadesc

All other references will be removed by the custom funtion that we have added previously.

James

Brian Potter
2 months ago

So, this is what my custom theme code would look like:


/**

 * When updating an existing record, allow only a specific list of fields to be updated.

 *

 * @param array $fields list of fields

 * @param string $method

 *

 * @return array

 */

function ticket_4965_iwp_import_mapper_permissions($fields, $method){


 if($method === 'update'){


  $result = array();


  // add list of all fields that you want to keep

  $fields_to_keep = array(

   '_yoast_wpseo_opengraph',

   '_yoast_wpseo_metadesc'

  );


  // pick only allowed fields.

  foreach($fields_to_keep as $field_id){

   $result[$field_id] = isset($fields[$field_id]) ? isset($fields[$field_id]) : '';

  }


  return $result;

 }


 return $fields;

}

add_filter('iwp/import_mapper_permissions', 'ticket_4965_iwp_import_mapper_permissions', 10, 2);

Brian Potter
2 months ago

Thanks for the reply and congratulations on the baby!! So, to be totally
clear: I want to use post_id as the KEY for what posts to update. I need to
edit the PHP snippet you sent me to include these custom fields (these are
the ones I want to update):

_yoast_wpseo_opengraph
_yoast_wpseo_metadesc

Will this snippet work with custom fields?

Can you please provide screenshots of what settings I should use when
running the import? Do I add the references to those fields during the
import like this:

[image: image.png]

James Collings Support Agent
2 months ago

Hi Brian,

Sorry for the delay in getting back to you, i have been on paternity leave the past 2 weeks so im trying to catch up.

If you have the post_id for each record, then you should be able to enable update permissions only (this will only allow the importer to update existing records).

Now we can use the filter iwp/import_mapper_permissions to clear all data being imported except for the name of the custom fields you want to import by adding the following function to your themes function file or adding the attached file to your wp-content/mu-plugins (adding a list of custom fields that you want to update to the variable named $fields_to_keep:

<?php


/**
 * When updating an existing record, allow only a specific list of fields to be updated.
 *
 * @param array $fields list of fields
 * @param string $method
 *
 * @return array
 */
function ticket_4965_iwp_import_mapper_permissions($fields, $method){

 if($method === 'update'){

  $result = array();

  // add list of all fields that you want to keep
  $fields_to_keep = array(
   'product_sku',
   'post_custom_field_1'
  );

  // pick only allowed fields.
  foreach($fields_to_keep as $field_id){
   $result[$field_id] = isset($fields[$field_id]) ? isset($fields[$field_id]) : '';
  }

  return $result;
 }

 return $fields;
}
add_filter('iwp/import_mapper_permissions', 'ticket_4965_iwp_import_mapper_permissions', 10, 2);

Please make sure you backup your database and files before running this code to make sure you do not loose any data.

James

Brian Potter
2 months ago

Hi there. Just purchased the plugin. I need to update ONLY custom fields to EXISTING content (posts/pages/products). I don’t want to update the content title, or excerpt. I have the “post_id” for each post. How do I run an “Update” import?