下面的代码是一个实现您所需功能的示例。看见tax_query 了解更多信息。
function my_get_posts( $query ) {
// we only need to modify the query for logged in users
if ( !is_user_logged_in() ) return $query;
$current_user = wp_get_current_user();
// assuming that user\'s region is stored as user_region meta key
$user_region = get_user_meta( $current_user->ID, \'user_region\', true );
$query->set( \'tax_query\', array(
array(
\'taxonomy\' => \'region\',
\'field\' => \'slug\',
\'terms\' => $user_region
)
));
return $query;
}
add_filter( \'pre_get_posts\', \'my_get_posts\' );