我有一个名为directory\\u listing的帖子类型,我有一个名为“place”的分类法,我有place1和place2的税收术语。我需要在自定义页面模板中显示所有使用分类法“place”中术语place2的“directory\\u listing”帖子。
就我所知,我迷路了。
<?php
$pages = get_posts(array(
  \'post_type\' => \'directory_listing\',
  \'numberposts\' => -1,
  \'tax_query\' => array(
    array(
      \'taxonomy\' => \'place\',
      \'field\' => \'slug\',
      \'terms\' => (\'place2\'),
      \'include_children\' => false
    )
  ))
);
foreach ($pages as $page) {
      echo $pages->post_title . \'<br/>\';
      echo $pages->post_content . \'<br/>\';
      echo $pages->slug . \'<br/><br/>\';
}
?>
 
                    最合适的回答,由SO网友:Abhik 整理而成
                    为什么会这样$pages 突然变成$myposts!!? 无论如何,我真的没有发现你的代码有什么大问题,但是,你可以试试这个。。
<?php
$pages = get_posts(array(
  \'post_type\' => \'directory_listing\',
  \'posts_per_page\' => -1,
  \'tax_query\' => array(
    array(
      \'taxonomy\' => \'place\',
      \'field\' => \'slug\',
      \'terms\' => \'place1\',
      \'include_children\' => false
    )
  ))
);
foreach ($pages as $page) {
      echo $page->post_title . \'<br/>\';
      echo $page->post_content . \'<br/>\';
      echo $page->slug . \'<br/><br/>\';
}
?>