How to get Custom Post ID by adding filter to child theme’s function

How to get Custom Post ID by adding code to child theme’s function. The following code works fine for the regular post, but can’t figure out for the custom post types.

add_filter( 'manage_posts_columns', 'revealid_add_id_column', 5 );
add_action( 'manage_posts_custom_column', 'revealid_id_column_content', 5, 2 );

function revealid_add_id_column( $columns ) {
   $columns['revealid_id'] = 'ID';
   return $columns;
}

function revealid_id_column_content( $column, $id ) {
   if( 'revealid_id' == $column ) {
   echo $id;
 }
}

2 Answers
2

add_action( 'manage_posts_custom_column', 'id_data' );
add_filter( 'manage_posts_columns', 'id_column'  );
function id_column( $defaults ) {
    $defaults['id'] = 'ID';
    return $defaults;
}
function id_data( $column_name ) {
    global $post;
    switch ( $column_name ) {
    case 'id':
        echo $post->ID;
    }
}

Leave a Comment