How to Specify the Order of Custom Column and Existing Column
Question
Can you please take a look at this code and let me know how I can change the order of added custom coulmn. As you can see I am adding 3 columns DifficultyLevel
, ShortTitle
, ShortText
but these are all adding to the end of column
Name | Date | Project | Level | Stage | Phase
but what I want is display them in this order
Level | Phase | Project | Name | Stage | Date
add_filter('manage_posts_columns', 't4a_remove_unwanted_columns');
add_filter('manage_posts_columns', 't4a_add_post_columns', 5);
add_action('manage_posts_custom_column', 't4a_get_post_column_values', 5, 2);
// Remove unwanted columns
function t4a_remove_unwanted_columns($defaults){
unset($defaults['title'],$defaults['date']);
return $defaults;
}
// Add new columns
function t4a_add_post_columns($defaults){
// field vs displayed title
$defaults['DifficultyLevel'] = __('Level');
$defaults['ShortTitle'] = __('Stage');
$defaults['ShortText'] = __('Phase');
return $defaults;
}
// Populate the new columns with values
function t4a_get_post_column_values($column_name, $postID){
if($column_name === 'DifficultyLevel'){
echo get_post_meta($postID,'DifficultyLevel',TRUE);
}
elseif($column_name === 'ShortTitle'){
echo get_post_meta($postID,'ShortTitle',TRUE);
}
elseif($column_name === 'ShortText'){
echo get_post_meta($postID,'ShortText',TRUE);
}
}
0
4 months
0 Answers
21 views
0
Leave an answer
You must login or register to add a new answer .