您可以使用pre_get_posts
过滤器,允许您在执行查询之前更改查询。通过这种方式,您可以将类别A添加到任何类别请求中。像这样:
add_filter (\'pre_get_posts\', \'wpse380282_add_cat_a\');
function wpse380282_add_cat_a ($query) {
// do this only on the front end for the main query if it is a category archive
if ( !is_admin() && $query->is_main_query() && is_category() ) {
// get the ID for Cat A
$cat_id = get_cat_ID (\'Cat A\');
// get category of the query (returns an array of current categories)
$cats = $query->get( \'cat\' );
// add Cat A to the array of current categories
$cats[] = $cat_id;
// set the category query to the expanded array
$query->set( \'cat\', $cats );
}
}