使用当前页面分类术语填充数组数据

时间:2014-05-23 18:06:32

标签: wordpress custom-taxonomy

我在页面模板中使用它,我希望有一个解决方案来填写' XXXXX'当前术语选择的分类区' place'。我不认为我可以在数组中执行do_shortcode。我不是很擅长php或wordpress。提前谢谢。

$pages = get_posts(array(
  'post_type' => 'directory_listing',
  'posts_per_page' => -1,
  'tax_query' => array(
    array(
      'taxonomy' => 'place',
      'field' => 'id',
      //'terms' => 'the-damn-bar',
      'terms' => 'XXXXX',
      'include_children' => false
    )
  ))
);



foreach ($pages as $mypost) {
      echo '<div class="specialList">';
      echo $mypost->post_content . '<br/>';
      echo '</div>';
}
?>

1 个答案:

答案 0 :(得分:0)

这里使用的WordPress函数是get_terms(),虽然这将返回与该分类法相关的所有术语;

$terms = get_terms(
    'place'
);

Codex:http://codex.wordpress.org/Function_Reference/get_terms

有一些相关的功能可能会让生活更轻松。

此外,包括我自己在内的一些人更喜欢使用WP_Query()而不是get_posts()。使用你的情况要好得多,在其他人中嵌套了post循环。

相关问题