Please write below code into functions.php
<?php
add_filter( 'manage_edit-products_columns', 'my_edit_products_columns' ) ;
function my_edit_products_columns( $columns ) {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Products' ),
'prod_cat' => __( 'Category' ),
'date' => __( 'Date' )
);
return $columns;
}
add_action( 'manage_products_posts_custom_column', 'my_manage_products_columns', 10, 2 );
function my_manage_products_columns( $column, $post_id ) {
global $post;
switch( $column ) {
/* If displaying the 'genre' column. */
case 'prod_cat' :
/* Get the genres for the post. */
$terms = get_the_terms( $post_id, 'prod_cat' );
/* 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( '<a href="%s">%s</a>',
esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'prod_cat' => $term->slug ), 'edit.php' ) ),
esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'prod_cat', 'display' ) )
);
}
/* Join the terms, separating them with a comma. */
echo join( ', ', $out );
}
/* If no terms were found, output a default message. */
else {
_e( 'No Genres' );
}
break;
/* Just break out of the switch statement for everything else. */
default :
break;
}
}
?>
No comments:
Post a Comment