Home › Forums › Add-ons › Flexible Content Field › update_field for flexible content field error
Hi guys!
I have some problem with update FC field, i spend too much time for understand, but i can not, mb someone can help me.
I need copy some field to another field, this is part of my code
function wph_copymetadata(){
$args = array(
'numberposts' => -1,
'post_type' => 'post',
);
$posts = get_posts( $args );
foreach($posts as $post){ setup_postdata($post);
$postid = $post->ID;
if (have_rows('content_blocks', $postid)) {
$field_key = "field_558bf9c9a9492";
//$components_value=[];
//$components_value=array();
$components_value = get_field($field_key, $postid);
while ( have_rows('content_blocks', $postid) ) : the_row();
// get layout
$layout = get_row_layout();
if( $layout === 'story_text' ) {
$story_text_title = get_sub_field('title');
$story_text_subtitle = get_sub_field('subtitle');
$story_text_content = get_sub_field('content');
$acf_fc_layout = "text";
$array_text_layout_values = array(
"acf_fc_layout" => $acf_fc_layout,
'title' => $story_text_title,
'subtitle' => $story_text_subtitle,
'content' => $story_text_content
);
$components_value[] = $array_text_layout_values;
//array_push($components_value, $array_text_layout_values);
} elseif( $layout === "story_image" ) {
$story_image_caption = get_sub_field('caption');
$story_image_subcaption = get_sub_field('subcaption');
$story_image_image = get_sub_field('image');
$story_image_portrait = get_sub_field('portrait');
$acf_fc_layout = "image";
$array_image_layout_values = array(
"acf_fc_layout" => $acf_fc_layout,
'caption' => $story_image_caption,
'subcaption' => $story_image_subcaption,
'image' => $story_image_image,
'format' => $story_image_format
);
$components_value[] = $array_image_layout_values;
//array_push($components_value, $array_image_layout_values);
}
endwhile;
}
if (!empty($components_value)) {
update_field( $field_key, $components_value, $postid );
}
}
wp_reset_postdata();
}
but after i have error in dashboard, and my data not display at dashboard
Warning: Illegal offset type in isset or empty in D:\OpenServer\domains\new\wp-content\plugins\advanced-custom-fields-pro\pro\fields\flexible-content.php on line 718
Warning: Illegal offset type in isset or empty in D:\OpenServer\domains\new\wp-content\plugins\advanced-custom-fields-pro\pro\fields\flexible-content.php on line 232
Also i try to display my data before update, its look like
Array ( [0] => Array ( [title] => [subtitle] => [content] => some text here[acf_fc_layout] => text )
[1] => Array ( [title] => [subtitle] => [content] =>some text here [acf_fc_layout] => text ) [2] => Array ( [title] => [subtitle] => [content] => some text here [acf_fc_layout] => text ) [3] => Array ( [title] => SHOP THE STORY [link_text] => [link] => [products] => Array ( [0] => 2204 [1] => 91494 [2] => 48693 ) [acf_fc_layout] => product_grid ) )
can anyone tell me what am I doing wrong ?
You need to use the field key for the flexible content field and all of the sub fields when adding content to a post for the first time.
The topic ‘update_field for flexible content field error’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.