On our site we let users block eachother and if user A blocks user B then user B should not see listings posted by user A.
I have tried to use the filter hook like this:
add_filter( 'hivepress/v1/models/listing', 'exclude_listings_from_blocked_users', 10, 2 );
function exclude_listings_from_blocked_users( $props, $model ) {
$current_user_id = get_current_user_id(); // Get the current viewer (user B)
// Get the list of users who have blocked the current user
$blocked_by_users = bb_moderation_get_blocked_by_user_ids( $current_user_id );
// Ensure the list excludes the current user (just in case)
if ( ! empty( $blocked_by_users ) && in_array( $current_user_id, $blocked_by_users ) ) {
$blocked_by_users = array_diff( $blocked_by_users, [ $current_user_id ] );
}
if ( ! empty( $blocked_by_users ) ) {
// Exclude listings from users who have blocked the current user
$props['args']['author__not_in'] = $blocked_by_users;
}
return $props;
}
But that doesn’t work. It won’t exclude any listings by user A even though the id of user A is included in the array $blocked_by_users.
I would be very grateful for some hints how to accomplish this.