I create a meta custom input to make a page builder. So i can drop & drag element to build content for post.
And when i save post, i want it will save directly to post content.
So i think i will change the $_POST and hook it to save_post action.
$_POST['content'] = $_POST['page-builder-content'];
I have try but it does not work. Any advises ? Code:
function stPageBuilder() {
$screens = array('post', 'page');
foreach ($screens as $screen)
{
add_meta_box(
'st-post-class', // Unique ID
esc_html__( 'Page Builder', page-builder' ), // Title
'stPageBuilderCallBack', // Callback function
$screen, // Admin page (or post type)
'advanced', // Context
'default' // Priority
);
}
}
function stPageBuilderCallBack($post, $box) {
wp_nonce_field( basename( __FILE__ ), 'st-page-builder-nonce' );
// here is html layout for drag & drop feature
}
function stPageBuilderSave($postID)
{
if ('page' == $POST['post_type']) {
if (!current_user_can('edit_page', $postID)) return;
} else {
if (!current_user_can('edit_post', $postID)) return;
}
if (!isset($_POST['st-page-builder-nonce']) || !wp_verify_nonce($_POST['st-page-builder-nonce'], basename(__FILE__))) return;
$_POST['content'] = $_POST['st-page-builder-content'];
}
function staddPageBuilder() {
add_action( 'add_meta_boxes', 'stPageBuilder' );
add_action( 'save_post', 'stPageBuilderSave' );
}
staddPageBuilder();