How to add a custom column in custom post type list in admin side wordpress

For add a custom column in admin side list for custom post type or any post type just copy and paste below code into your theme's functions.php


function rj_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}_posts_custom_column' , 'rj_display_rank_column_data', 10, 2 ); orignal hook
add_action( 'manage_portfolio_posts_custom_column' , 'rj_display_rank_column_data', 10, 2 );
function rj_add_rank_column( $columns ) {
   
        $columns['rank'] = __( 'Rank', 'enfold' );
        return $columns;
}
//add_filter( 'manage_{custom_post_type}_columns' , 'rj_add_rank_column' );  orignal hook
add_filter( 'manage_portfolio_columns' , 'rj_add_rank_column' ,20);

Comments

Popular posts from this blog

How to add image option in nav menu in wordpress

How to change user id on checkout page for assign order to different user in woocommerce wordpress

How to add a custom sorting or order by option on category archive or product archive page in woocommerce wordpress