-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wp_insert_post( $args ) #17200
Comments
+1 |
6 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
Here's a dirty workaround that worked with my case.
For me it worked as I wanted to publish many posts at once with a certain template blocks, I hope that would help until this feature is applied. |
I didn't test it with core blocks, but the below method works fine with ACF blocks (so I would think it does with core stuff as well). 1. Post type registrationfunction cpt_mac_submenus() {
$labels = array( //... );
$args = array(
// ...
'template' => array(
array( 'acf/submenus--title-and-description', array(
'lock' => array(
'move' => true,
'remove' => true,
),
) ),
array( 'acf/submenus--output-navigation', array(
'lock' => array(
'move' => true,
'remove' => true,
),
) ),
array( 'acf/submenus--single-image', array(
'lock' => array(
'move' => true,
'remove' => true,
),
) ),
),
'template_lock' => 'all',
);
register_post_type( 'mac-submenus', $args );
}
add_action( 'init', 'cpt_mac_submenus' ); 2. Insert (custom post type) post with default content$content = '<!-- wp:acf/submenus--title-and-description /--><!-- wp:acf/submenus--output-navigation /--><!-- wp:acf/submenus--single-image /-->';
$new_submenu_post_args_Arr = array(
'post_title' => $title,
'post_type' => 'mac-submenus',
'post_status' => 'draft',
'post_author' => 1,
'post_content' => $content,
);
wp_insert_post( $new_submenu_post_args_Arr ); Basically, the |
i believe wp_insert_post needs to be extended to have knowledge of the template. https://developer.wordpress.org/reference/functions/wp_insert_post/ so either use the registered gutenberg template, if no content is inserted or add means to merge data with the blocks inside the gutenberg template :) ref: |
i have searched through the issues/related issues and i have been unable to find a solution...
i need to include the gutenberg registered template when creating a new post programmatically.
i have registered a custom post type "credits" via php which includes the following arguments:
i am unable to programmatically add a new post which includes the gutenberg "template" array.
i have been able to output the following:
... which pulls in the gutenberg paragraph block successfully (rather than pulling it into the "classic" editor). however, i need it to pull in the template of blocks the same way it does when adding a new post from the wordpress backend.
for context, using php i have hooked into learndash:
... i need to find a solution to achieve this, even if it requires using a different method ( other than wp_insert_post ) to achieve the desired result. any help or direction would be appreciated.
The text was updated successfully, but these errors were encountered: