Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type "career_opportunities" with a "responsibilities" textarea box:

<p><label for="responsibilities">Responsibilities</label></p>
                    <?php wp_editor(
                                    "", 
                                    "responsibilities", 
                                    array(
                                        'textarea_name' => 'responsibilities',
                                        'tinymce'=>true
                        )); ?>

The problem is, it is not saving when I call "save_post":

add_action( 'save_post', 'save_career_opportunity' );


    /* When the post is saved, saves our custom data */
    function save_career_opportunity( $post_id ) {

        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
          return;

        if( !isset( $_POST['career_nonce'] ) || !wp_verify_nonce( $_POST['career_nonce'], 'my_meta_box_career_nonce' ) )
                return;

        if ( 'page' == $_POST['post_type'] ) 
        {
            if ( !current_user_can( 'edit_page', $post_id ) )
                return;
        } else {
            if ( !current_user_can( 'edit_post', $post_id ) )
                return;
          }

            $responsibilities  = $_POST['responsibilities']; // longer description
            $qualifications    = $_POST['qualifications']; // longer description
            $career_level      = $_POST['career_level']; // 
            $minimum_education = $_POST['minimum_education'];
            $job_status        = $_POST['job_status'];

            update_post_meta($post_id, 'responsibilities', $_POST['responsibilities']);
            update_post_meta($post_id, 'qualifications', $_POST['qualifications']);
            update_post_meta($post_id, 'career_level', $_POST['career_level']);
            update_post_meta($post_id, 'minimum_education', $_POST['minimum_education']);
            update_post_meta($post_id, 'job_status', $_POST['job_status']);

    }
share|improve this question
    
Is there any reason you're using TinyMCE and not just a regular <textarea>/<input />? –  m0r7if3r Feb 27 '12 at 22:32
    
the other fields get saved? any reason why you store the $_POST data to vars but don't use them in the script? –  ungestaltbar Feb 27 '12 at 22:33
    
@ungestaltbar The other fields "career_level", "minimum_education" etc are getting saved...just not the "responsibilities" field –  redconservatory Feb 27 '12 at 22:38
    
I am using TinyMCE because I anticipate the client will want rich text, but if this is simply a bad idea with custom meta_boxes let me know (it works this way with pods?) –  redconservatory Feb 27 '12 at 22:39
    
Your WP Editor function first, the content argument is missing. Are you sure that the data does not get saved or does it just not appear after saving because you don't reassign the saved data to the first (missing) argument of wp editor? –  ungestaltbar Feb 28 '12 at 6:27
add comment

1 Answer

up vote 1 down vote accepted

In regards to the comment @ungestaltbar posted on your question, this is what they meant. You are storing the $_POST data into variables but then not using them, rendering them useless. This won't solve your issue but I wanted to clear that up. :)

Alternatively, you can see exactly what is getting passed to the next page. I cleaned up the code a bit, try this and find out if the responsibilities data is even getting passed to it. This would be the first thing I would do to debug your issue.

add_action( 'save_post', 'save_career_opportunity' );

/* When the post is saved, saves our custom data */
function save_career_opportunity( $post_id ) {

     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
          return;

      if( !isset( $_POST['career_nonce'] ) || !wp_verify_nonce( $_POST['career_nonce'], 'my_meta_box_career_nonce' ) )
          return;

    if ( 'page' == $_POST['post_type'] ) {
        if ( !current_user_can( 'edit_page', $post_id ) )
            return;
    } else {
        if ( !current_user_can( 'edit_post', $post_id ) )
            return;
    }

    die( var_dump( $_POST ) ); // See exactly what is being passed to this function

    extract( $_POST );

    update_post_meta( $post_id, 'responsibilities', $responsibilities );
    update_post_meta( $post_id, 'qualifications', $qualifications );
    update_post_meta( $post_id, 'career_level', $career_level );
    update_post_meta( $post_id, 'minimum_education', $minimum_education );
    update_post_meta( $post_id, 'job_status', $job_status );

}

If not then we can safely assume it has nothing to do with the function you are using to save the post, but the issue lies with (probably) wp_editor or your meta box itself. Try this and see what happens, if you are unable to see the responsibilities data after changing your code to the above, then we may need to see more of your meta box code.

share|improve this answer
add comment

Your Answer

 
discard

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.