Support

Account

Forum Replies Created

  • Hi

    I am attempting a very similar thing to you but having the same problem. When I add a block, type some content into the editor, then deselect the block, and reselect it, the values I entered are missing.

    I have stripped it all back to a really simple test in my functions.php file as follows:

    acf_register_block(array(
    	'name'			=> 'my_test',
    	'title'			=> __('Test'),
    	'description'		=> __('A Test'),
    	'render_callback'	=> 'render_test',
    
    ));
    
    function render_test() {
    	$title = get_field('title');
    	$content = get_field('content');
    
    	?>
    
    		<h2><?php echo $title ?></h2>
    		<?php echo $content ?>
    
    	<?php
    }

    My template is simply:

    <?php get_header(); ?>
    
    <?php the_content() ?>
    
    <?php get_footer(); ?>

    I am using 5.8-beta3. I am at a bit of a loss as to what is going on. If anyone could give me any suggestions, I would really appreciate it!!

    Many thanks
    David

  • Hi

    I am attempting a very similar thing to you but having the same problem. When I add a block, type some content into the editor, then deselect the block, and reselect it, the values I entered are missing.

    I have stripped it all back to a really simple test in my functions.php file as follows:

    acf_register_block(array(
    	'name'			=> 'my_test',
    	'title'			=> __('Test'),
    	'description'		=> __('A Test'),
    	'render_callback'	=> 'render_test',
    
    ));
    
    function render_test() {
    	$title = get_field('title');
    	$content = get_field('content');
    
    	?>
    
    		<h2><?php echo $title ?></h2>
    		<?php echo $content ?>
    
    	<?php
    }

    My template is simply:

    <?php get_header(); ?>
    
    <?php the_content() ?>
    
    <?php get_footer(); ?>

    I am using 5.8-beta3. I am at a bit of a loss as to what is going on. If anyone could give me any suggestions, I would really appreciate it!!

    Many thanks
    David

  • I am still working on this and am slowly progressing forward, I have now managed to get it to add the layout using the following code:

    $field_data = acf_get_field($field);
    
    $key = uniqid();
    
    $field_data['layouts'][$key] = array(
    	'display' => 'block',
    	'key' => $key,
    	'label' => 'Test',
    	'max' => '',
    	'min' => '',
    	'name' => 'test',
    	'sub_fields' => $sub_fields
    );
    acf_update_field($field_data);

    The problem is, no matter what I pass as the sub_fields, they get stripped out by the update_field method on the flexible content plugin before the save is called on line 1334:

    function update_field( $field ) {
    		
    		// loop
    		if( !empty($field['layouts']) ) {
    			
    			foreach( $field['layouts'] as &$layout ) {
    		
    				unset($layout['sub_fields']);
    				
    			}
    			
    		}
    		
    		
    		// return		
    		return $field;
    	}

    I am not quite sure why this would be? Is there a way that I can re-add the sub_fields to the layout afterwards?

    A note to anyone else that stumbles upon this, using acf_update_field does not refresh the cached version in the acf-json folder so you need to remove those files if you want to use this method.

    Any input would be greatly appreciated!!

    All the best
    David

Viewing 3 posts - 1 through 3 (of 3 total)