Support

Account

Home Forums Gutenberg How to save block data in Beta4 when field group key == name? Reply To: How to save block data in Beta4 when field group key == name?

  • OK, although I don’t like it, it cannot be discussed, so finally I’ve updated my keys to be named with “field_” prefix and run SQL replace on post_content.

    I’m leaving here a temporary function I’ve used as it may be helpful for someone:

    add_action( 'init', 'myprefix_update_fields_keys' );
    function myprefix_update_fields_keys() {
    	global $wpdb;
    if ( current_user_can('administrator') && isset( $_GET['upkeys'] ) && $_GET['upkeys'] == 1 ) :
    	echo "Replacement started!<br>";
    	$p = 'myprefix-';
    	$fields = array(
    		"{$p}myblock-title",
    		"{$p}myblock-content",
    		// Many other fields
    	);
    	foreach ( $fields as $field ) :
    		$wpdb->query( 			
    				"
    				UPDATE $wpdb->posts
    				SET post_content = REPLACE(post_content, '\"$field\"', '\"field_$field\"')
    				WHERE post_content LIKE '%\"$field\"%'
    				"
    		);
    	endforeach;
    	echo "Replacement ended!";
    endif;
    }