WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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) 
            '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' );

share|improve this question
Why do you want to save meta box content into post content? – Vinod Dalvi May 22 '13 at 9:29
I create a custom metabox content instead for post's editor. If i want to it present in front page, so i need to save it into post content. – Quang Trung Nguyen May 22 '13 at 9:39
ok. I got it but the above code that you have added in question does not display any textbox or textarea to enter content in it. Did you miss to copy it here or you have not created it? – Vinod Dalvi May 22 '13 at 9:55
in function stPageBuilderCallBack i will include a form to do it. I sure have a custom value, the only thing we need to save this value to post content – Quang Trung Nguyen May 22 '13 at 10:03
up vote 1 down vote accepted

The answer appears to be clear if you look at the source code. The action you're hooking to occurs inside wp_insert_post, and is called just before it returns the $post_ID variable. This means that all the manipulation and data insertion has already taken place, so modifying the $_POST array will do nothing. You must look for things to do prior to database modification for your changes to have any effect. Luckily, WordPress has many options to choose from.

In short, here's what I would do:

//  Hook to a different action / filter
function staddPageBuilder() {
    // ...
    add_filter( 'wp_insert_post_data', 'stPageBuilderSave', 10, 2);

// Notice the new filter passes different arguments, so we need to adapt the function
function stPageBuilderSave($data, $postarr) 
    // Since we don't have the $postID variable, let's try to grab it from the array passed by the insert function
    // Note that passing the object ID to the current_user_can function is very unusual and you can do without it
    $postID = isset($postarr['ID']) ? $postarr['ID'] : 0;

    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;

    // This bit changes, because the action is different and so are the function's arguments
    $data['post_content'] = $_POST['st-page-builder-content'];
    return $data;

Let us know how it goes!

share|improve this answer
Yes, that is what i need. Thank you very much ! – Quang Trung Nguyen May 22 '13 at 10:07
Glad it helped :) – Tomas Buteler May 22 '13 at 10:54

Did you try using wp_insert_post function from WordPress to insert post into post content


// Create post object
$my_post = array(
  'post_title'    => 'My post',
  'post_content'  => 'This is my post.',
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => array(8,39)

// Insert the post into the database
wp_insert_post( $my_post );
share|improve this answer
He's already hooking to an action inside wp_insert_post. Calling this function within his existing logic can cause an infinite loop. You should clarify what you intend for him to do. – Tomas Buteler May 22 '13 at 10:01
This will create another post, not update an existing one. You could use wp_update_post() on the save_post hook, but beware the infinite loop: codex.wordpress.org/Plugin_API/Action_Reference/… – Stephen Harris May 22 '13 at 10:01
Plus what @StephenHarris said; always with the sharper eye :) – Tomas Buteler May 22 '13 at 10:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.