Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ahmedmusawir/b8f83ca413127cbc700e30207d1019dc to your computer and use it in GitHub Desktop.

Select an option

Save ahmedmusawir/b8f83ca413127cbc700e30207d1019dc to your computer and use it in GitHub Desktop.
PLUGIN-DEV - ADD ADMIN COLUMNS
function __construct()
{
add_filter( 'manage_posts_columns' , array( $this, 'add_views_column' ) );
add_action( 'manage_posts_custom_column' , array( $this, 'add_data_into_views_column' ), 5, 2 );
}
public function add_views_column( $columns ) {
$columns['post_views'] = __('Views');
$columns['featured_image'] = __('Featured Image');
return $columns;
}
function add_data_into_views_column( $column_name, $postID ) {
// print_r($column_name);
if ( $column_name === 'post_views' ) {
echo get_post_meta( $postID, 'views', true );
}
if ( $column_name === 'featured_image' ) {
// Give the Post Thumbnail a class "alignleft".
echo get_the_post_thumbnail( $postID, 'thumbnail', array( 'class' => 'alignleft' ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment