Yoast SEO将主要术语ID存储为post meta字段_yoast_wpseo_primary_{taxonomy}
. 知道了这一点,您可以使用元查询来获取具有主类别ID的所有帖子X
:
$query = new WP_Query([
\'cat\' => \'X\', // Just in case Yoast data corrupted & post no longer attached to X term but primary meta remains
\'meta_query\' => [
[
\'key\' => \'_yoast_wpseo_primary_category\',
\'value\' => \'X\',
]
],
]);