Hi,
I would like to create a new page with wp_insert_post() -function and add some of my own acf blocks with content to the page. However I am only able to add default WP blocks to the page, but not acf blocks. Any tips on how to add acf blocks with content to the page?
Code that works (default WP blocks only):
wp_insert_post(
array(
‘post_title’ => ‘Test Post’,
‘post_type’ => ‘page’,
‘post_content’ => ‘
<!– wp:heading {“placeholder”:”Post Heading”} –>
<h2>Here is the title</h2>
<!– /wp:heading –>
<!– wp:paragraph {“placeholder”:”Post Paragraph”} –>
<p>here is some text</p>
<!– /wp:paragraph –>’,
‘post_status’ => ‘publish’,
‘post_author’ => 1,
)
);
What I am trying to do but not able to(add acf blocks):
wp_insert_post(
array(
‘post_title’ => ‘Test Post’,
‘post_type’ => ‘page’,
‘post_content’ => ‘
<!– acf:my-example-block –>
<!– /acf:my-example-block –>’,
‘post_status’ => ‘publish’,
‘post_author’ => 1,
)
);
Furthermore, I would like to add some content to the blocks like:
wp_insert_post(
array(
‘post_title’ => ‘Test Post’,
‘post_type’ => ‘page’,
‘post_content’ => ‘
<!– acf:my-example-block {“data”:[“content”:”here is the content to the acf field called content”]} –>
<!– /acf:my-example-block –>’,
‘post_status’ => ‘publish’,
‘post_author’ => 1,
)
);
Thanks for any help in advance!