Add Custom Column To Custom Post Type
For Adding Titles
manage_{$post_type}_posts_columns
// Add the custom columns to the supplier post type:
add_filter( 'manage_supplier_posts_columns', 'set_custom_edit_supplier_columns' );
function set_custom_edit_supplier_columns($columns) {
// unset( $columns['author'] );
$columns['website_url'] = __( 'Website URL', 'twentytwentytwo' );
$columns['mode_of_data_sync'] = __( 'Mode of data sync', 'twentytwentytwo' );
$columns['status'] = __( 'Status', 'twentytwentytwo' );
return $columns;
}
For Adding Columns data
manage_{$post_type}_posts_custom_column
// Add the data to the custom columns for the supplier post type:
add_action( 'manage_supplier_posts_custom_column' , 'custom_supplier_column', 10, 2 );
function custom_supplier_column( $column, $post_id ) {
switch ( $column ) {
case 'website_url' :
/*$terms = get_the_term_list( $post_id , 'website_url' , '' , ',' , '' );
if ( is_string( $terms ) )
echo $terms;
else
_e( 'Unable to get author(s)', 'twentytwentytwo' );
break;*/
case 'website_url' :
echo get_post_meta( $post_id , 'website_url' , true );
break;
case 'mode_of_data_sync' :
echo get_post_meta( $post_id , 'mode_of_data_sync' , true );
break;
case 'status' :
echo get_post_meta( $post_id , 'status' , true );
break;
}
}
Comments
Post a Comment