WordPress按术语ID或名称显示帖子

时间:2017-01-21 作者:abdel

我有一个项目类型:别墅,住房。。。这部分代码不显示任何内容:

$aProjectArgs = array(
            \'post_type\' => \'uni_project\',
            \'posts_per_page\' => -1,
            \'orderby\' => \'menu_order\',
            \'order\' => \'asc\',
            \'tax_query\' => array(
    array(
    \'taxonomy\' => \'post_tag\',
    \'field\' => \'id\',
    \'terms\' => 45
     )
  )

i tried also :

$aProjectArgs = array(
            \'post_type\' => \'uni_project\',
            \'posts_per_page\' => -1,
            \'orderby\' => \'menu_order\',
            \'order\' => \'asc\',
            \'tax_query\' => array(
    array(
    \'taxonomy\' => \'post_tag\',
    \'field\' => \'name\',
    \'terms\' => \'Villa\'
     )
  )
但是什么都不显示,有人能帮我吗?

1 个回复
SO网友:aomanansala

您可以从WordPress文档中尝试此代码https://developer.wordpress.org/reference/functions/query_posts/

$args = array(
    \'post_type\'=> \'movie\',
    \'actor\'    => \'Bruce Campbell, Chuck Norris\',
    \'order\'    => \'ASC\'
);
query_posts( $args );
然后按如下方式显示

while(have_posts()) : the_post();
    <!-- your code here -->
endwhile;

相关推荐

Order by taxonomy Value

我确实想每年订购CTP。我有一个分类法叫做“annee”(年份),还有一个CTP叫做“moto”(摩托车)。问题是,当我试图按分类法排序时,它只按分类法ID排序,而不是按分类法值排序。你有什么解决办法吗?if ( is_post_type_archive( \'motos\' ) ) { $query->set( \'posts_per_archive_page\', 24 ); $query->set( \'order\', \'DESC\' );&