I am trying to add a column in admin table listing of my custom post type cota
that is the current taxonomy tipo
but it's not printing it.
Here's the current code:
function la_set_cota_columns($columns){
$newColumns = array();
$newColumns['title'] = 'Título da Cota';
$newColumns['comissao'] = 'Comissão';
$newColumns['proprietario'] = 'Proprietário';
$newColumns['vencimento'] = 'Vencimento';
$newColumns['tipo'] = 'Tipo de Cota';
return $newColumns;
}
add_filter('manage_cota_posts_columns', 'la_set_cota_columns');
function la_cota_custom_column($column, $post_id){
$content = get_post_meta($post_id);
switch( $column ){
case 'comissao' :
echo $content['comissao'][0];
break;
case 'proprietario' :
echo $content['proprietario'][0];
break;
case 'vencimento' :
echo $content['vencimento'][0];
break;
case 'tipo':
echo get_metadata('cota', $post_id, 'tipo', $single = true);
break;
}
}
add_action('manage_cota_posts_custom_column', 'la_cota_custom_column', 10, 2);
Actual results can be found here
Thanks a lot in advance.
So you are looking to print the terms associated with the current post listed in the table... As such, you instead need to use the wp_get_post_terms function:
$term_names = wp_get_post_terms($post_id, 'tipo', array('fields' => 'names')); // returns an array of term names
echo implode(', ', $term_names);
Ans just one little comment about the function call you did use: the last parameter is optional, which means you can either pass a value or nothing at all. If you omit it, it will have the default value false. But you don't pass the default value when you make the function call:
get_metadata('cota', $post_id, 'tipo', true);
Hope this helps!