WordPress

How To Add A Custom Column In Custom Post Type List In Admin Side WordPress

Here we learn about how to add a custom column in custom post type list in the admin side WordPress.

Custom code copied and paste into your child theme’s functions.php file.

<?php
function myblog_display_rank_column_data( $column, $post_id ) {
  global $wpdb;
  switch ( $column ) {
    case 'rank' :
      $rank = get_post_meta( $post_id, 'optimus_rank_field', true );
      if( $rank != '9999' && $rank != '' ) {
        echo $rank;
      } else {
        echo '-';
      }
      break;
  }
}
// add_action( 'manage_{custom_post_type}_custom_column' , 'myblog_display_rank_column_data', 10, 2 ); orignal hook
add_action( 'manage_posts_custom_column' , 'myblog_display_rank_column_data', 10, 2 );
function myblog_add_rank_column( $columns ) {    
  $columns['rank'] = __( 'Rank', 'enfold' );
  return $columns;
}
//add_filter( 'manage_{custom_post_type}_columns' , 'myblog_add_rank_column' );  orignal hook
add_filter( 'manage_posts_columns' , 'myblog_add_rank_column' ,20);
?>

OUTPUT:

Rahul Prajapat

I’m Rahul Prajapat. I’m a WordPress developer and Author at TheCodeHubs. I have good skill of Html, CSS, JQuery, SQL, Web API, PSD to HTML/PSD to WordPress, WordPress Theme/Plugin Customization, create or modify short code, customize visual composer short code or integrate new short code with visual composer, can create custom metabox for any post type in WordPress admin.

Share
Published by
Rahul Prajapat

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago