So I'm making a customer service portal using Wordpress, and it's been pretty good so far. To preface, I have a few relevant custom fields.
Customers have "isSalesperson" == No. Salespeople have "isSalesperson" == Yes. Then a salesperson has a "salespersonID" equivalent to a number. All of their customers have a salespersonID equivalent to that same number. There's also "super" which means you can see all customers. I want to only list the clients that have the same salespersonID as the salesperson when they are looking at this page.
$admin = wp_get_current_user();
$salespersonID = $admin->salespersonID;
if($salespersonID != "Super"){
$meta_query_args = array(
'relation' => 'AND',
array(
'key' => 'salespersonID',
'value' => $salespersonID,
)
);
}
else
{
$meta_query_args = array(
'relation' => 'AND',
array(
'key' => 'salespersonID',
'value' => 0,
'compare' => '!=',
)
);
}
$meta_query = new WP_Meta_Query( $meta_query_args );
$args = array(
'meta_key' => 'companyname',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => $meta_query,
);
$users = get_users($args);
foreach ( $users as $user ) {
if($user->isSalesperson == "No"){
echo '<option>' . $user->companyname . '</option>';
}
}
My issue is that I'm not sure how to use the WP_Meta_Query in order to select only the users that meet the criteria of their salespersonID being equivalent to the current logged-in user's salespersonID. Currently, the code runs without error but doesn't actually do what I want. It simply shows all of the results.