一种选择是使用某种查找表,可以是硬编码的,也可以是settings page, 将角色(用户组)映射到类别(城市)的位置。然后使用current user object 获取基于城市的角色,并将其用作从查找表中获取类别ID的键,在post query.
伪代码示例,
// Current user data
$current_user = wp_get_current_user();
// Get city role
$city_based_role = some_function_to_get_city_role_from_roles($current_user->roles);
// Get category id
$city_category = some_function_to_get_category_id_from_role_to_category_lookup_table($city_based_role);
// Query posts for category
$args = array(
// some args
\'cat\' => $city_category,
);
$query = new WP_Query($args);