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;
}
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.