根据分类 slug 获取 post 类型

Get post types based on taxonomy slug

简而言之, 如果我有一个分类 slug 'category' 或 'post_tag',并且我不知道哪个 post 类型有这个分类。

那么我怎么知道所有 post 类型都有这个分类法?

谢谢

要获取分配给任何类别或标签的 post-type 的帖子,您可以使用以下新的 WP_Query 函数:

对于类别分类法:

$args = array('post_type' => 'post_type_slug', 'category_name' => 'category_slug_name', 'posts_per_page' => 10, 'orderby' => 'title', 'order' => 'ASC');
$query = new WP_Query($args);

对于标签:

$args = array('post_type' => 'post_type_slug', 'tag' => 'tag_name', 'posts_per_page' => 10, 'orderby' => 'title', 'order' => 'ASC');
$query = new WP_Query($args);

编写查询后,循环发布帖子:

if($query->have_posts()):
   while($query->have_posts()): $query->the_post();
       echo get_the_title();
       echo get_the_content();
   endwhile;
endif;

希望对您有所帮助。

我找到了解决方案。

我只有 taxonomy/tag 的鼻涕虫 - 'post_tag'

获取 Post-Types 其中有 'post_tag' taxonomy/tag

$post_types = get_taxonomy( 'post_tag' )->object_type;

That-sit,我通过 taxonomy/tag.

获得了 post-types

谢谢。