duanqi5114 2017-01-24 20:08
浏览 37
已采纳

根据帖子ID获取自定义帖子类型的分类

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.

  • 写回答

1条回答 默认 最新

  • douxing2156 2017-01-24 20:38
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度