Support

Account

Home Forums Add-ons Flexible Content Field WordPress Editor as Flexible Content Layout Reply To: WordPress Editor as Flexible Content Layout

  • So I can thus far save my flexible content field layout to post_content with:

    //save field content to the_content
    function save_to_the_content( $value, $post_id )
    {
    		wp_update_post( array( 'ID' => $post_id, 'post_content' =>  $value ) );
    		return $value;
    }
    add_filter('acf/update_value/key=field_5318e88463d1e', 'save_to_the_content', 10, 3);

    I’m still struggling with getting it to work the opposite way – post_content to flexible content layout. I’m able to sort of accomplish it with this:

    //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( $value, $post_id, $field )
    {
    
    $field_key = "field_5318e86463d1d";
    $value = get_field($field_key);
    
    $page = get_post();
    $string = $page->post_content;
    
    if(!multi_in_array("the_content", $value) && $string != '') :
    	$value[] = array("text" => $string, "acf_fc_layout" => "the_content");
    	update_field( $field_key, $value, $post_id );
    endif;
    }
    
    add_action('save_post', 'save_to_acf_layout');
    

    I’m struggling to get both functions working together. And my second function is imperfect – doesn’t work exactly how I’d like. Thoughts?