首先,代码读起来很乱,一些格式肯定会帮你找到答案。也就是说documentation on WP_Query 和一些要引导的示例代码
$args = array(
    \'post_status\' => \'publish\',
    \'tax_query\'   => array(
        array(
            \'taxonomy\' => \'category\',
            \'field\'    => \'slug\',
            \'terms\'    => \'your_cat_slug\'
        )
    ) 
);
$posts = new WP_Query( $args );
 我使用了“tax\\u query”而不是“category\\u name”,因为我觉得它更灵活,同时更容易理解(因此也更容易使用),如果您在理解代码方面有任何问题,请阅读文档,WP\\u query的文档记录得太好了,太疯狂了。
编辑更新的代码
$cats = array();
foreach( get_the_category() as $cat ) {
    $cats[] = $cat->cat_ID;
}
$args = array(
    \'post_status\'    => \'publish\',
    \'posts_per_page\' => -1,
    \'tax_query\' => array(
        array(
            \'taxonomy\'         => \'category\',
            \'field\'            => \'id\',
            \'terms\'            => $cats,
            \'include_children\' => false
        )
    )
);
print_r( WP_Query( $args ) as $post );