【问题标题】:get_categories() only returns categories in useget_categories() 只返回正在使用的类别
【发布时间】:2012-06-24 16:15:41
【问题描述】:
$args = array(
"type"      => "post",      
"orderby"   => "name",
"order"     => "ASC");

$types = get_categories($args);

执行此操作时。 $types 仅包含“未分类”,因为它被用作我帖子的默认值。还有其他可用的类别,但除非我有使用它们的帖子,否则它们不会返回。 如何返回所有可能的类别,而不仅仅是正在使用的类别?

【问题讨论】:

  • 如果您正在阅读此 QA 并且仍然没有运气,您可能需要根据本指南 @987654321 在您的 get_categories' 参数中将 hide_empty 设置为 false @

标签: php wordpress plugins


【解决方案1】:
<?php $args = array("hide_empty" => 0,
                    "type"      => "post",      
                    "orderby"   => "name",
                    "order"     => "ASC" );
      $types = get_categories($args);
?>

【讨论】:

【解决方案2】:

为此,我建议使用:

wp_list_categories( $args );

关于此功能及使用方法的进一步说明:http://codex.wordpress.org/Template_Tags/wp_list_categories

【讨论】:

  • 我正在使用我创建的参数,只是在发布此问题时忘记将其输入参数括号中。不过感谢您的通知。
猜你喜欢
  • 1970-01-01
  • 2013-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-03
  • 1970-01-01
相关资源
最近更新 更多