Learn Tutorials Point - LTP > WordPress > How to Adding custom columns to custom post types in WordPress
How to Adding custom columns to custom post types in WordPress
The hooks to create custom columns and their associated data for a custom post type are manage_{$post_type}_posts_columns and manage_{$post_type}_posts_custom_column respectively, where {$post_type} is the name of the custom post type. in WordPress
This example from the documentation removes the author column and adds a taxonomy and metadata column:
// Add the custom columns to the book post type: add_filter( 'manage_book_posts_columns', 'set_custom_edit_book_columns' ); function set_custom_edit_book_columns($columns) { unset( $columns['author'] ); $columns['book_author'] = __( 'Author', 'your_text_domain' ); $columns['publisher'] = __( 'Publisher', 'your_text_domain' ); return $columns; } // Add the data to the custom columns for the book post type: add_action( 'manage_book_posts_custom_column' , 'custom_book_column', 10, 2 ); function custom_book_column( $column, $post_id ) { switch ( $column ) { case 'book_author' : $terms = get_the_term_list( $post_id , 'book_author' , '' , ',' , '' ); if ( is_string( $terms ) ) echo $terms; else _e( 'Unable to get author(s)', 'your_text_domain' ); break; case 'publisher' : echo get_post_meta( $post_id , 'publisher' , true ); break; } }
Author: Learn Tutorials Point
We Well organized and easy-to-understand Interactive tutorials With lots of examples of how to use Tutorials WordPress, PHP, Bootstrap, Bootstrap 4, HTML, CSS, AJAX, jQuery, Woocommerce, Post, Database, Javascript, Theme, Responsive, Templates.
Trending Posts
Tags
ACF
Ading custom columns
admin
Bootstrap
Cart Price
categories
Change Price
class
Code
comments
Create
Creating custom post Type
CSS
current
custom
Customizing
Custom Post
Custom Post Type
Custom Taxonomy
database
Date
Fatch
form
function
HTML
Image
Install
javascript
jQuery
Menu
PHP
Post
Post Type
Price
product
responsive
Resular price
Single product
Table
taxonomy
Theme
Title
woocommerce
Wordpress
Wordpress Code