Add Categories column to custom post type in WordPress

Add-Categories-column-to-custom-post-type-in-wordpress

This code is used for the list of all post-show this list you add one more column in the categories column.

Taxonomy is = solutionsconsole
solutions is = Post Type

<?php 
add_filter( 'manage_solutions_posts_columns', 'my_edit_movie_columns' ) ;

function my_edit_movie_columns( $columns ) {
 $columns['solutionsconsole'] = __( 'Categories', 'your_text_domain' );
    return $columns;
} 

add_action( 'manage_solutions_posts_custom_column' , 'custom_book_column', 10, 2 );
function custom_book_column( $column, $post_id ) {
    global $post;
 switch( $column ) {

 case 'solutionsconsole' :

 /* Get the solutions for the post. */
 $terms = get_the_terms( $post_id, 'solutionsconsole' );

 /* If terms were found. */
 if ( !empty( $terms ) ) {

 $out = array();

 /* Loop through each term, linking to the 'edit posts' page for the specific term. */
 foreach ( $terms as $term ) {
 $out[] = sprintf( 
 esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'solutionsconsole', 'display' ) )
 );
 }

 /* Join the terms, separating them with a comma. */
 echo join( ', ', $out );
 }
 
 /* If no terms were found, output a default message. */
 else {
 _e( 'No Categories Solutions' );
 }

 break;

 /* Just break out of the switch statement for everything else. */
 default :
 break;
 }
}
?>
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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact us

Fill in the form below or give us a call and we'll contact you. We endeavour to answer all enquiries within 24 hours on business days.