繁体   English   中英

在自定义帖子的自定义分类法下显示术语的帖子

[英]Showing posts of a term under a custom taxonomy of a custom post

我创建了一个自定义Electronics帖子。 然后, Electronics有一个自定义分类appliences appliances有诸如home applianceskitchen appliances类的术语。现在, home appliances有一些职位。

现在,我要显示home appliances术语下的帖子。 我创建了一个页面taxonomy-appliances.php

---- Electronics (custom post)
      |__ appliances (custom taxonimy)
          |__home appliances
             |__ posts
             |
          |__Kitchen appliances
             |_posts

如何在该页面上显示?

这是我的代码:

<?php

    $args = array(
            'tax_query' => array(
                array(
                    'taxonomy' => 'appliances',
                    'field' => 'slug',
                    'terms' => 'home appliances',
                )
            )
        );
    $posts = new WP_Query($args);

    if($posts->have_posts()){
        while ($posts->have_posts()) : $posts->the_post();

            echo get_the_title();

        endwhile;
    }

?>

但是什么都没有显示

$args = array(
  'post_type' => 'electronics', // your post type name
  'posts_per_page' => -1,
  'tax_query' => array(
    array(
      'taxonomy' => 'appliances', //your taxonomy name
      'field' => 'slug',
      'terms' => 'home-appliances',//here use the slug, check the slug of your term

    )
  )
);
 Try this, 

  $posts_array = get_posts(
    array(
        'posts_per_page' => -1,
        'tax_query' => array(
            array(
                'taxonomy' => 'appliances',
                'field' => 'slug',
                'terms' => 'home-appliances',
            )
        )
    )
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM