Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在帖子/页面中打印自定义帖子类型类别名称_Php_Arrays_Wordpress - Fatal编程技术网

Php 如何在帖子/页面中打印自定义帖子类型类别名称

Php 如何在帖子/页面中打印自定义帖子类型类别名称,php,arrays,wordpress,Php,Arrays,Wordpress,我已经在谷歌上搜索了很多时间来找到解决这个问题的方法。我正在使用dream主题灵活的wordpress主题。我想在第个公文包页面中打印dt_公文包自定义帖子类型的类别名称。我已经尝试了很多方法来做到这一点。但是没有用。 最后,我坚持使用以下代码: $ctname = get_the_terms( get_the_ID(), 'dt_portfolio_category' ); print_r ($ctname); 这给了我如下输出: Array ( [27] => stdClass Ob

我已经在谷歌上搜索了很多时间来找到解决这个问题的方法。我正在使用dream主题灵活的wordpress主题。我想在第个公文包页面中打印dt_公文包自定义帖子类型的类别名称。我已经尝试了很多方法来做到这一点。但是没有用。 最后,我坚持使用以下代码:

$ctname = get_the_terms( get_the_ID(), 'dt_portfolio_category' );
print_r ($ctname);
这给了我如下输出:

Array ( [27] => stdClass Object ( [term_id] => 27 [name] => Magazine [slug] => magazine [term_group] => 0 [term_taxonomy_id] => 33 [taxonomy] => dt_portfolio_category [description] => [parent] => 0 [count] => 3 [object_id] => 8560 [filter] => raw ) ) 

我想打印这个数组中的slug。请帮我做这件事。

你可以这样做:

  if($ctname ) {
      foreach($ctname as $data){

          $slug[] = $data->slug;

        }
       print_r($slug); // value inside slug array
    }
如果$ctname只有1个数组,那么只需使用$slug而不是$slug[] 在foreach循环中


希望它能对你有所帮助

看一看,效果很好。我得到了我所期望的结果。非常感谢@Jenis Patel