I have successfully added a custom column to the WordPress back-end, but can’t get sorting to register.
The page below was helpful.
http://www.elliotcondon.com/advanced-custom-fields-admin-custom-columns/
The ‘type’ field shows on the ‘press’ post-type but without sorting. No error is returned.
Here is my code below:
// ADD NEW COLUMN
function ST4_columns_head($defaults) {
$defaults['type'] = 'Type';
$defaults['featured_image'] = 'Featured Image';
return $defaults;
}
// SHOW THE FEATURED IMAGE
function ST4_columns_content($column_name, $post_ID) {
if ($column_name == 'featured_image') {
echo get_the_post_thumbnail( $post_ID, 'tiny', $attr );
}
if ($column_name == 'type') {
echo get_field( "type", $post_ID );
}
}
add_filter('manage_press_posts_columns', 'ST4_columns_head');
add_action('manage_press_posts_custom_column', 'ST4_columns_content', 10, 2);
//make the new column sortable
function my_press_sortable_columns( $columns ) {
$columns['type'] = 'type';
return $columns;
}
add_filter( 'manage_press_sortable_columns', 'my_press_sortable_columns' );
I know there are plugins that can do this, but I avoid plugins that can be replaced with a few lines of code.
Thank you for your insights.
E