这是未经测试的,但试一试。首先获取分类法中术语名称的列表。然后根据regex过滤返回的名称数组。然后将过滤后的名称数组用于WP查询。
// assumes these assignments:
//
// $taxonomy - the taxonomy name you are querying against
// $regex - the regex to match the term names against
// First get all the terms that have posts:
$terms = get_terms( array(
\'taxonomy\' => $taxonomy,
\'fields\' => \'names\', // return an array of term names
) );
$filtered_terms = preg_grep($regex, $terms);
// when you use this, expand $args with other relevant arguments for your query, such as post type:
$args = array(
\'tax_query\' => array(
array(
\'taxonomy\' => $taxonomy,
\'field\' => \'name\',
\'terms\' => $filtered_terms,
),
),
)
$the_query = new WP_Query( $args );
// Then run your loop