you can create conditionnal arguments like that :
$user_args = [
'orderby' => 'display_name',
'order' => 'asc',
'meta_query' => array(
array(
'key' => 'verifier_assign_country',
'value' => $countryCode,
'compare' => '='
),
)
];
if ("" !== $univCode) {
$user_args["meta_query"][] = array(
'key' => 'verifier_assign_univ',
'value' => $univCode,
'compare' => 'LIKE'
);
}
$users = get_users($user_args);
Related Posts:
- Content hooks vs User hooks
- Job of meta_key meta_value fields in database tables
- how to delete all users and posts based on ‘user_meta’?
- get_*_meta doesn’t always return an array
- Like & Dislike functionality using JavaScript
- cannot get user_registered date from get_user_meta
- Display current user’s custom post meta in sidebar
- Show number of posts by logged in user
- Retrieve user_meta and copy to post_meta
- Array of user ids to list of user names
- get Insert id for meta field
- help to decipher wp metadata
- Check For get_post_meta on Author Archive Page
- Sort users by custom user meta value
- Hide username from blog post source code
- How do I retrieve the slug of the current page?
- Most efficient way to get posts with postmeta
- Get posts by meta value
- Explanation of update_post_(meta/term)_cache
- How to extract data from a post meta serialized array?
- user_login vs. user_nicename
- How to save an array with one metakey in postmeta?
- WordPress is stripping escape backslashes from JSON strings in post_meta
- Adding fields to the “Add New User” screen in the dashboard
- How can I get the post ID from a WP_Query loop?
- Difference between update_user_meta and update_user_option
- Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
- How to filter users on admin users page by custom meta field?
- get_user_meta() doesn’t include user email?
- How to update_post_meta value as array
- Adding meta tag without plugin
- What’s the point of get_post_meta’s $single param?
- What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
- How to edit a post meta data in a Gutenberg Block?
- Automatically delete inactive users after 2 months
- Check if user is admin by user ID
- Sanitizing integer input for update_post_meta
- post formats – how to switch meta boxes when changing format?
- Execute action after post is saved with all related post_meta records (data)
- Lack of composite indexes for meta tables
- Return all users with a specific meta key
- Get a single post by a unique meta value
- if get_post_meta is empty do something
- Where the Nickname is being used in WordPress
- How we get_post_meta without post id
- How get post id from meta value
- What is the code to get the download link for a product in WooCommerce?
- Safe to delete blank postmeta?
- How to display custom user meta from registration in backend?
- Allowing an email as the username?
- Grouping users under parent user
- advanced custom fields update_field for field type: Taxonomy
- update_post_meta not saving when value is zero
- get_users is expecting unserialized meta_value
- Can I count the number of users matching a value in a multiple value key?
- Meta compare with date (stored as string) not working
- How to get users by a custom field / by user meta data?
- How to create a template for a custom URI associated with the user
- Trying to get custom post meta through Jetpack JSON API [closed]
- How to order users alphabetically by their last name?
- Getting all user metadata from user
- How to update/insert custom field(post meta) data with wordpress REST API?
- Restrict post edit/delete based on user ID and custom field
- How do you add a custom option to user data?
- Extending WP_User class and using this sub-class during the whole lifecycle
- get_post_meta returning empty string when data shows in the database
- publish_post action hook doesn’t give post_meta_data
- Wp_User_Query not sorting by meta key
- Remove WordPress.org Meta link
- Remove post meta keys
- Add a button to users.php
- How to access the post meta of a post that has just been published?
- Why time functions show invalid time zone when using ‘c’ time format?
- How we can get the user id by its display_name
- Why is get_post_meta returning an array when I specify it as single?
- WP_User_Query with combined meta query – not working?
- How to use hyperdb to separate and share a user dataset between wordpress installs?
- LEFT JOIN, INNER OUTER JOIN, LEFT OUTER JOIN is driving me crazy. Please help?
- \WP_User Object | What’s the Difference Between {caps} and {allcaps}?
- How to update/delete array in post meta value?
- Show Biographical Info while creating new user
- How to get all term meta for a taxonomy – getting term_meta for taxonomy
- Adding an assisting editor box to Post page
- include user profiles in search results?
- How to add follow functionality to multi-author wordpress site?
- Search multiple meta keys at once
- How may I filter get_users() similarly to pre_get_posts?
- delete unused postmeta
- Should I sanitize custom post meta if it is going to be escaped later?
- Where to Store Custom User Fields
- Add post meta based on another post meta value before publish post
- How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
- Plugin that would allow WordPress Authors to “follow” other Authors and query “Activity Info” from that
- Front-end update_post_meta snippet displays white screen?
- Query between two meta values?
- Save both current and new version of post meta
- Get Advanced Custom Fields values before saving [closed]
- Querying Email Addresses for a List of Users with Same Last Name?
- Give extra post-meta to RSS feeds
- Display sortable User meta column in admin panel user’s page