Hello,
How to return all users in foreach are selected game A.
Mr Bean have selected game A (field acf checkbox A)
Mlle Andrew have selecte game A and B (field acf checkbox A/B)
How to return a foreach with same :
foreach only game A loop
Mr Bean and Mlle andrew
Thanks for help
Hi @shepxbfr
You would need to use the WP_User_Query
If you check the ACF docs on checkboxes, you can see how to query them here
So something like:
<?php
$args = array(
'role' => 'subscriber',
'meta_query' => array(
array(
'key' => 'game',
'value' => '"A"',
'compare' => 'LIKE'
)
)
);
// The Query
$user_query = new WP_User_Query( $args );
// User Loop
if ( ! empty( $user_query->get_results() ) ) {
foreach ( $user_query->get_results() as $user ) {
echo '<p>' . $user->display_name . '</p>';
}
} else {
echo 'No users found.';
}
?>