Home › Forums › Add-ons › Flexible Content Field › WordPress Editor as Flexible Content Layout › Reply To: WordPress Editor as Flexible Content Layout
So I’m almost there:
//multi-dimensional array in_array
function multi_in_array($value, $array)
{
foreach ($array as $item)
{
if (!is_array($item))
{
if ($item == $value)
{
return true;
}
continue;
}
if (in_array($value, $item))
{
return true;
}
else if (multi_in_array($value, $item))
{
return true;
}
}
return false;
}
function save_to_acf_layout( $content, $post_id )
{
$field_key = 'field_5318e86463d1d'; //flexible content key
$value = get_field($field_key);
if(get_page_template_slug( $post_id ) === '') :
if(!multi_in_array('the_content', $value)) :
$value[] = array('text' => $content, 'acf_fc_layout' => 'the_content');
update_field( $field_key, $value, $post_id );
else :
$value[0] = array('text' => $content, 'acf_fc_layout' => 'the_content');
update_field( $field_key, $value, $post_id );
endif;
else :
$flex_content = $value[0]['text'];
wp_update_post( array( 'ID' => $post_id, 'post_content' => $flex_content ) );
endif;
return $content;
}
add_filter( 'content_edit_pre', 'save_to_acf_layout', 10, 2 );
add_filter( 'content_save_pre', 'save_to_acf_layout', 10, 2 );
But now I’m stuck with this infinite loop. I’ve tried removing the filters but when I do wp_update_post doesn’t run. Ideas?
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.