6

I have extended class WP_List_Table to create a custom sortable table of posts along with a quick edit box with custom meta boxes.

The meta boxes populate and save but when I click submit the field values disappear and the defaults ( cb, title, tags, cats, etc) which are not even included in my class get added back to the column saved. This throws off the other columns on the page. The saved custom field values return when the page is refreshed.

It seams like on submit the $post_object is missing.

I'm using a hacked get_inline_data function that includes the meta_values in my quick edit form instead of calling get_inline_data in my class.

My save function for the meta boxes:

add_action( 'save_post', 'save_inline_edit_meta' );
function save_inline_edit_meta( $post_id  ) {
    global $pagenow;

    if ( $pagenow == 'admin.php' ) {
     if ( isset( $_POST[ 'is_quickedit' ] )  && isset( $_POST[ 'standinghead' ] ) )
        update_post_meta( $post_id, '_wnd_standing_head', $_POST[ 'standinghead' ] );

    if ( isset( $_POST[ 'is_quickedit' ] )  && isset( $_POST[ 'headline' ] ) )
        update_post_meta( $post_id, '_wnd_alt_title', $_POST[ 'headline' ] );

    if ( isset( $_POST[ 'is_quickedit' ] )  && isset( $_POST[ 'deck' ] ) )
        update_post_meta( $post_id, '_wnd_deck', $_POST[ 'deck' ] );
    }
  return $post_id;

}

My Javascript save function:

save : function(id) {
        var params, fields, page = $('.post_status_page').val() || '';

        if ( typeof(id) == 'object' )
            id = this.getId(id);
        $('table.widefat .inline-edit-save .waiting').show();
        params = {
            action: 'inline-save',
            post_ID: id,
            post_type: 'post',
            edit_date: 'true',
            post_status: page
        };
        fields = $('#edit-'+id+' :input').serialize();
        params = fields + '&' + $.param(params);

        $.post('admin-ajax.php', params,
            function(r) {
                $('table.widefat .inline-edit-save .waiting').hide();

                if (r) {
                    if ( -1 != r.indexOf('<tr') ) {
                        $(inlineEditPost.what+id).remove();
                        $('#edit-'+id).before(r).remove();
                        $(inlineEditPost.what+id).hide().fadeIn();
                    } else {
                        r = r.replace( /<.[^<>]*?>/g, '' );
                        $('#edit-'+id+' .inline-edit-save .error').html(r).show();
                    }
                } else {
                    $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
                }
            }
        , 'html');
        return false;
    },

enter image description here

1
  • 1
    I'm trying to do the same, but I haven't found any nice information about it, it seems you are the only one there building a custom table and trying to put some custom fields on the quick edit, can you share it ? :-) May 11, 2012 at 18:26

1 Answer 1

5

I just run in the same error when adding extra columns to the default post types.

The offending line was the $pagenow check.
Quick Edit uses admin-ajax.php so it doesn't renders the custom columns when it's done.

This doesn't work:

if( 'edit.php' == $pagenow && is_admin() )
{
    add_action( 'admin_init', array( $this, 'init_id_column' ), 999 );
    add_action( 'admin_init', array( $this, 'init_thumb_column' ), 999 );
}

But this does:

if( 
    ( 'edit.php' == $pagenow && is_admin() ) 
    or
    ( 'admin-ajax.php' == $pagenow && 'inline-save' == $_POST['action'] && 'list' == $_POST['post_view'] )
)
{
    add_action( 'admin_init', array( $this, 'init_id_column' ), 999 );
    add_action( 'admin_init', array( $this, 'init_thumb_column' ), 999 );
}

I'm not sure if it's the best method to do this checking, though...

Related track ticket.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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