我在WP管理员的帖子中添加了一个特色图片栏。除了使用“快速编辑”功能外,所有这些都可以正常工作。更新后,该列将消失,或者更确切地说,ajax保存函数不会返回该列。列标题保持不变,但正在更新的行不再具有特征图像单元格,导致行末尾出现“空白”单元格(所有默认单元格向左移动)。
我不知道该从哪里解决这个问题,也没有找到任何答案。
谢谢你的帮助。
编辑:下面是添加自定义列的代码。过滤器和操作在插件的\\uu构造中调用
// 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\');
}
}
}