Hello!
I’ve been trying to update a Post Object field for a while now, but I haven’t had any luck.
I do call update_field()
and my $value
is an array
This code is within a foreach loop, that iterates over some db records:
$per_obj = get_page_by_title( $resp, OBJECT, 'persona' );
if (!is_null($per_obj)) {
$responsables_arr[] = $per_obj;
}
update_field( $nombre_cargo, $responsables_arr, $post_id );
When that code executes, everything seems to work fine, but later, when I open the post where the field was updated, said field displays this message:
PHP Notice: Object of class WP_Post could not be converted to int in C:\xampp\htdocs\wordpress\wp-content\plugins\advanced-custom-fields\core\fields\post_object.php on line 402
What could I do? I don’t know what other details I could give you(?
ACF Version is 4.4.12 (Free version)
WP Version is 4.9.4
Thanks in advance!
I think you are trying to pass an array in the update field function and you haven’t defined a field. I think you need to pass a number to the post object. You may want to add another variable to get the page ID.
Whatever $nombre_cargo is, you need to use the field name or field key as the first parameter of the update field function. For example: ‘nombre_cargo’ or ‘field_123456890’
Try this, but replace the name of the field first.
$per_obj = get_page_by_title( $resp, OBJECT, 'persona' );
if (!is_null($per_obj)) {
$page = per_obj->ID;
}
update_field( 'cargo_number', $page, $post_id );