You’ve used LIKE
comparison method, that means every similar expression will be matched, including exact string and similar string.
If you want to match exact string, you should use =
operator.
Example:
global $current_user;
$user_roles = $current_user->roles;
$user_role_query = array();
for ($i=0; $i < sizeof($user_roles); $i++) {
$user_role_query[] = array(
'key'=>'attribution_roles',
'value' => $user_roles[$i],
'compare'=>'='
);
}
I suggest read WP_Query page in WordPress codex for details about comparison methods, relation ways, etc.
Hope it works for you 😉
Related Posts:
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Custom WP_Query order by post_meta and (author) user_meta
- Query WooCommerce orders where meta data does not exist
- Perform query with meta_value date
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Meta Query for specific months
- How to orderby meta_value_num with dollar ($) sign
- Optional Meta Query
- Overwrite YoastSEO meta-tags with another page’s [closed]
- How to orderby multiple meta fields if some fields are empty
- Meta Query relation “AND” then set array accordingly
- How to set up hierarchical relationships without using plugins / meta query
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- Why doesn’t my WP Meta Query return any results?
- WP_Query meta compare must include ALL array values
- meta_query where the meta value is not the post title
- Query multiple post types, but different order for each
- Woocommerce Get Orders By Meta Value
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- Meta query orderby meta_value_num sorting by role first
- Query against multiple locations within single custom post type post
- Strange results from WP_Query
- WP Query. Ordering posts by another post types meta
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- Query by meta value (add a dropdown of all values)
- Meta query doesn’t remove placeholder escape before query
- What is the best way to reset a search on a meta_key / meta_value?
- How can I modify standard search query to include also ACF custom fields values?
- WP_Query using meta_query with LIKE doesn’t return what it should
- Use meta query only 3 or more results?
- Use value from meta key array for use in WP_Query
- Meta_query compare operator explanation
- meta_query ‘compare’ => ‘IN’ not working
- Sorting: custom query with orderby meta_value_num THEN by title
- WP_Query with checkbox meta_query
- What is the most efficient way of querying posts based on visits and date for current day?
- Meta Query with date and time on the same Day before given time
- How to grab metabox value in wp_query meta_query key
- Order posts by tags count?
- Add and in the header while looping over custom query in page template
- Which custom query am I in and how can I access its properties & methods?
- How can I create a WP_Query that returns posts where one meta_value
- How to count data records in wordpress which have same meta_value in wp_postmeta table?
- How to speed up wp_query, took more 5s to run against 100k posts
- How do you query wordpress posts using a math formula between multiple meta field values?
- Minimize database queries to user tables?
- Add condition of user capability in WP_query
- Query all published post AND attachment with specific mime type
- Get all products which have both product category
- How to make Meta Query case sensitive?
- unable to retrive parent page information
- Any number in meta key (wp query)
- Is it a good idea to improve meta query performance by adding tax query?
- How to display user order by role
- WP Query related posts by tags
- Order by summing multiple values
- Modify wp-query and sort by post meta key
- Orderby listing issue
- Make meta query treat meta_value as 1 or 0
- Query only the posts with a post format of “audio”
- pre_get_posts – Trying to get property of non-object warning
- WordPress query posts with multiple post_meta data
- Query post by date (stored custom field meta as yyyymmdd) and differentiate across 12 months
- WP Query Meta Value – How To Identify Specific, Unique Values?
- Order by meta_key doesn’t work
- Update query for wp_posts and wp_postmeta
- Multiple meta_key ordering with pre_get_posts
- Meta query with compare by more than 2 fields
- Insert images into wordpress post with a query
- meta_query returning excluded result
- meta_query weird behaviour, static int will work, but not user data
- Creating a query that get all posts but places meta items first
- wp query to use both author id and meta_query
- WP_Query for a taxonomy value OR a custom post type meta field
- pre_user_query vs pre_get_posts
- Adding nofollow to all the post links in get_posts with pre_get_posts or WP_Query
- Add to search posts query array with post IDS which will appear first
- post type => ‘any’ not applied my custom queries
- How to show terms from another taxonomy
- meta_query is not allowing to show posts when querying multiple arguments in a WP_Query
- My entry results are not consistently alphabetized
- Speed up WP_query with meta comparing dates
- Meta Query if Values Don’t Exist
- Ignoring ‘a’ when sorting posts
- How to show all the associated posts with specific date of data metabox?
- Is it possible to search for a string in posts OR postmeta?
- Custom query for tag and custom tag from 2 post type
- wpdb get_results() returns only 2 rows
- WordPress meta_query not working
- Using orderby with 2 meta keys
- wp_query – Modify $query to include duplicate content
- Optimising specific Query with ACF meta objects
- How to get several fields from wp_query?
- Pagination not working with WP_Query (creates links but no page)
- Passing conditional arrays to WP_Query() [closed]
- Query custom post type by date field only working when two posts match the query
- Divide WP_Query posts by date & post type
- Query Posts by date range with fixed beginning and end
- query by meta value then date and not empty meta value
- Get all user with both meta_value