Wordpress 如何通过taxanomy获得定制邮件?

Wordpress 如何通过taxanomy获得定制邮件?,wordpress,content-management-system,taxonomy,Wordpress,Content Management System,Taxonomy,我知道,我必须使用classwp\u query和一个循环,但是我无法从数据库中获取带有分类法(例如,category文档)的自定义帖子。我在读,我不得不使用模板“分类法-{slug}”,但我不知道,我如何才能得到这个分类法的帖子 例如,我单击了链接“并且我得到了带有post_类型“documents”和分类法类别documents”的帖子” 如何获取分类法private,并将该分类法放入我的$args中,用于Wp\u查询?请不要向我提供带有parse链接的变量。如果您使用自定义帖子类型,请将$

我知道,我必须使用class
wp\u query
和一个循环,但是我无法从数据库中获取带有分类法(例如,category文档)的自定义帖子。我在读,我不得不使用模板“分类法-{slug}”,但我不知道,我如何才能得到这个分类法的帖子

例如,我单击了链接“并且我得到了带有post_类型“documents”和分类法类别documents”的帖子”


如何获取分类法
private
,并将该分类法放入我的$args中,用于
Wp\u查询
?请不要向我提供带有parse链接的变量。

如果您使用自定义帖子类型,请将
$post\u type
的值更改为自定义帖子类型名称

$post_type = 'post';

// Get all the taxonomies for this post type
$taxonomies = get_object_taxonomies( (object) array( 'post_type' => $post_type ) );

foreach( $taxonomies as $taxonomy ) : 

  // Gets every "category" (term) in this taxonomy to get the respective posts
  $terms = get_terms( $taxonomy );

  foreach( $terms as $term ) : 

    $posts = new WP_Query( "taxonomy=$taxonomy&term=$term->slug&posts_per_page=2" );

    if( $posts->have_posts() ): while( $posts->have_posts() ) : $posts->the_post();
        //Do you general query loop here  
    endwhile; endif;

  endforeach;

endforeach;