Php 如何在WordPress中为自定义帖子类型的自定义类别循环帖子?

Php 如何在WordPress中为自定义帖子类型的自定义类别循环帖子?,php,wordpress,loops,Php,Wordpress,Loops,下面的代码循环了一个自定义帖子类型中的所有帖子。 我需要在自定义帖子类型中循环特定类别 <?php $query = new WP_Query( array( 'post_type' => 'case-study' ) ); if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); get_te

下面的代码循环了一个自定义帖子类型中的所有帖子。 我需要在自定义帖子类型中循环特定类别

<?php 
    $query = new WP_Query( array( 'post_type' => 'case-study' ) ); 
    if ( $query->have_posts() ) : 
        while ( $query->have_posts() ) : $query->the_post(); 

            get_template_part( 'template-parts/content', 'work' ); 

         endwhile;
    endif; 
?>


我需要为自定义帖子类型中的指定类别更改哪些内容?

您可以尝试以下操作:

$query = new WP_Query( array(
    'post_type' => 'case-study',          // name of post type.
    'tax_query' => array(
        array(
            'taxonomy' => 'category',   // taxonomy name
            'field' => 'term_id',           // term_id, slug or name
            'terms' => 48,                  // term id, term slug or term name
        )
    )
) );

您可以尝试以下操作:

$query = new WP_Query( array(
    'post_type' => 'case-study',          // name of post type.
    'tax_query' => array(
        array(
            'taxonomy' => 'category',   // taxonomy name
            'field' => 'term_id',           // term_id, slug or name
            'terms' => 48,                  // term id, term slug or term name
        )
    )
) );

尝试
'post\u type\u cat'=>'your category'
$query=new WP\u query('category\u name=your category')
$query=新的WP_查询('cat=1')好的,我将尝试一下。尝试
'post\u type\u cat'=>“您的类别”
$query=new WP\u query('category\u name=your category')
$query=新的WP_查询('cat=1')好的,我会尝试一下。这对我很有用。非常感谢你,我的朋友。这对我很有用。非常感谢你,我的朋友。