Se Pro Email è un campo di conferma (casella di controllo), impostare il parametro field_value della query su true funzionerà.
Dato che il tuo obiettivo è semplicemente verificare che il campo sia stato impostato, penso che questa versione della query sia più adatta. Rimuove il parametro field_value e verifica che il campo denominato sia stato impostato con (ucf.value = '') IS NOT TRUE. Questo restituirà false per qualsiasi utente che non ha impostato il campo e restituirà anche false per gli utenti che hanno impostato il campo e poi eliminato il valore inserito:
--[params]
-- string :field_name
-- string :group_name
WITH ucf_name AS(
SELECT
CONCAT('user_field_', id) AS name
FROM user_fields
WHERE name = :field_name
),
excluded_users AS (
SELECT
gu.user_id
FROM group_users gu
JOIN groups g
ON g.id = gu.group_id
WHERE g.name = :group_name
)
SELECT
u.id AS user_id
FROM users u
JOIN user_custom_fields ucf
ON ucf.user_id = u.id
WHERE ucf.name = (SELECT name FROM ucf_name)
AND (ucf.value = '') IS NOT TRUE
AND u.id NOT IN (SELECT user_id FROM excluded_users)
Se desideri che la query restituisca il valore del campo, modifica l’istruzione SELECT finale in:
SELECT
u.id AS user_id,
ucf.value
FROM users u
JOIN user_custom_fields ucf
ON ucf.user_id = u.id
WHERE ucf.name = (SELECT name FROM ucf_name)
AND (ucf.value = '') IS NOT TRUE
AND u.id NOT IN (SELECT user_id FROM excluded_users)