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 added a featured image column to my posts in the WP admin. This all works fine except when using the Quick Edit feature. Upon update, the column disappears, or rather isn't returned by the ajax save function. The column header remains, but the row being updated no longer has a featured image cell, resulting in a "blank" cell at the end of the row (all the default cells shifts left).

I'm unsure where to look to address this issue and haven't had any luck finding an answer.

Thanks for any help.

EDIT: Here is the code to add the custom column. The filter and action are called in the plugin's __construct

    // Set featured image columns
    add_filter('manage_edit-post_columns', array($this, 'set_custom_columns'));
    add_action( 'manage_post_posts_custom_column', array( $this, 'set_custom_column_data' ), 10, 2 );

    /**
     * Function to create featured image column
     * @param $columns
     * @return array
     */
    public function set_custom_columns($columns)
    {

        if ( !is_array( $columns ) ) {
            $columns = array();
        }

        $new_columns = array();

        foreach( $columns as $key => $label ) {
            if ( $key == 'title' ) { // Put the Thumbnail column before the Title column
                $new_columns['featured-image'] = __( 'Image', $this->plugin_slug );
            }

            $new_columns[$key] = $label;
        }

        return $new_columns;
    }

    /**
     * Display custom column data
     */
    public function set_custom_column_data( $column_name, $post_id ) {

        // If featured image column and a featured image exists, display it
        if ( 'featured-image' == $column_name ) {
            if ( has_post_thumbnail( $post_id ) ) {
                echo get_the_post_thumbnail($post_id, 'thumbnail');
            }
        }
    }
share|improve this question

marked as duplicate by brasofilo, s_ha_dum, toscho Nov 20 '13 at 9:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Could you show the code you used to add your custom column? –  Krzysiek Dróżdż Nov 13 '13 at 18:51

1 Answer 1

up vote 1 down vote accepted

I'm using Tom McFarlin's Plugin Boilerplate for the plugins I write and in the main plugin file, there is a conditional statement to keep things as light as possible in the admin:

if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
  ...
}

Since the Quick Edit feature uses AJAX, the column wasn't being recreated on a Quick Edit save. Changing the above line to:

if ( is_admin() ) {
  ...
}

solved the problem and the custom column appears when saving via Quick Edit.

Hopefully this helps someone who might run into the same type of issue.

Thanks.

share|improve this answer

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