I have additional ACF fields added to my users. One of those is a checkbox area where my users can check off all of the various departments that they personally belong to. Users can select as many as they want.
The field name is “department“.
And there are values available like:
- Social Work
- Criminal Justice
- Public Affairs
I want to show a list of all of my users that have checked the box for Social Work… even if they have also checked other box options as well.
Below is the short code that I am trying to build, however this returns me nothing. What am I missing to be able to pull out all users with Social Work Checked?
<?php
add_shortcode('show_valuesofstuff', function() {
?>
<!-- START CONTENT SECTION -->
<?php
$args1 = array(
'meta_key' => 'last_name',
'orderby' => 'meta_value',
'order' => 'ASC',
'exclude' => array(1,8,9),
'meta_query' => array(
'relation' => 'AND',
'department' => array(
'key' => 'department',
'value' => 'Social Work',
'compare' => 'IN',
),
)
);
$subscribers = get_users($args1);
echo '<ul>';
foreach ($subscribers as $user) {
echo '<li>' . $user->display_name.' ['.$user->phone_number . ']</li>';
}
echo '</ul>';
?>
<!-- END CONTENT SECTION -->
<?php
});// END SHORTCODE [show_valuesofstuff]?>
If anyone could provide suggestions, or example code, that would be excellent!
Thanks so much!