Rows with custom columns not well formatted after Quick Edit save
Question
I have a custom post type “promotion” made via code put on theme file functions.php.
I also added some columns to custom post type list.
They seems work fine, but if I Use the quick edit to update the post, the custom columns disappear on save action.
The code used to add the custom columns:
// ADD NEW COLUMN
function promo_columns_head($defaults) {
global $post_type;
if ( $post_type === 'promotion' ) {
$new = array();
foreach ($defaults as $k => $value){
if ($k !== 'author')
$new[$k] = $value;
else {
$new['valid_from'] = __('Valid From');
$new['valid_until'] = __('Valid Until');
$new['status'] = __('Status');
}
if ($k == 'cb') {
$new['image'] = __('Image');
$new['approvals'] = __('Approvals');
}
}
return $new;
} else {
return $defaults;
}
}
// HANDLE COLUMNS CONTENT
function promo_columns_content($column_name, $post_ID) {
global $post_type;
if ( $post_type === 'promotion' ) {
if ($column_name == 'approvals') {
// some code here to handle approval content
}
if ($column_name == 'image') {
// some code here to retrieve the right url of external image
echo '<img src="https://ur/of/external/image" alt="">';
}
if ($column_name == 'valid_from') {
the_field("valid_from");
}
if ($column_name == 'valid_until') {
the_field("valid_until");
}
if ($column_name == 'status') {
$statuses = get_post_statuses();
$status = get_post_status($post_ID);
echo "<span class="$status">$statuses[$status]</span>";
}
}
}
add_filter('manage_posts_columns', 'promo_columns_head');
add_action('manage_posts_custom_column', 'promo_columns_content', 10, 2);
Custom post type listing
Custom post type listing after saving update from quick edit
The custom columns are not present, author column (that I didn’t show) is now present
Any help are appreciated
0
custom-field, custom-post-types, quick-edit
3 years
2020-05-29T09:11:16-05:00
2020-05-29T09:11:16-05:00 0 Answers
91 views
0
Leave an answer