Hi,
I’m having a problem updating/appending rows in repeater fields. I’m trying to migrate all data from one table into user meta and keep getting the following error.
Catchable fatal error: Object of class WP_Error could not be converted to string in C:\wamp\www\baca\wp-content\plugins\advanced-custom-fields\core\fields\_functions.php
I’m not sure what I’m doing wrong as I’m following the resources at http://www.advancedcustomfields.com/resources/functions/update_field/ but not working. Below is the code I’m using. Can someone see whats wrong?
function add_members() {
global $wpdb;
$results = $wpdb->get_results( "SELECT * FROM members" );
foreach($results as $row) {
$new_user = array(
'user_login' => $row->CompanyName,
'user_pass' => wp_generate_password ( 12, false ),
'user_url' => $row->Website,
'user_email' => $row->Email,
'wp_capabilities' => 'Subscriber'
);
$pid = wp_insert_user($new_user);
if($pid) :
$field_key = "field_52f4fedbcdb79";
$post_id = $pid;
$value = get_field($field_key, $post_id);
$value[] = array(
"more_contacts_name" => $row->ContactName,
"more_contacts_email" => $row->ContactEmail,
"acf_fc_layout" => "row_1"
);
$value[] = array(
"more_contacts_name" => $row->ContactName2,
"more_contacts_email" => $row->ContactEmail2,
"acf_fc_layout" => "row_2"
);
update_field( $field_key, $value, $post_id );
endif;
}
}
add_action( 'edit_user_profile', 'add_members' );
Hi @chrisg
$post_id = $pid;
should be $post_id = "user_{$pid}";
Please also debug your code before using the update_field function to make sure all the data is correct.
it is most likely that $pid
is not what you think it is.
Thanks
E
Brilliant, thanks Elliot. Thats solved it. I didn’t realise you had to add a prefix to the newly created user id. Seems pretty obvious now as the id could be for anything.
Thanks
How to update the repeater sub field of each post.