I went with custom taxonomy instead of custom meta field and it works great (although I am still not sure why meta_query didn’t work)
I have saved custom taxonomy term for each attachment
wp_set_object_terms($post->ID, $slug, 'image_category' );
And custom query args are
$args = array(
'post_type' => 'attachment',
'posts_per_page' => 44,
'post_status' => 'inherit',
'post_parent' => null,
'tax_query' = array(
array(
'taxonomy' => 'image_category',
'field' => 'slug',
'terms' => $cat
)
)
);
Related Posts:
- Getting attachments by meta value
- Get attachment by meta_key value
- meta_query with meta values as serialize arrays
- Broken? WP_Query and “attachment” as a post type
- Use REGEXP in WP_Query meta_query key
- compare meta_query in get_posts arguments
- Is it possible to query all posts that don’t have an attachment?
- Display products from specific category in shop page
- How to Compare Two Meta Fields
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- How to paginate attachments in a secondary query as gallery?
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- Query by meta_key and order by meta_value_num return orderby date
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- Wp_query order by multiple custom fields?
- WordPress altering my custom query, How to fix it?
- How to query ‘posts_per_page’ to display a different blog posts index template?
- Order by meta_key in custom post type doesn’t affect the query
- How to create/modfiy WP_Query to search in post title OR custom field?
- How to get user_id from wordpress database inside ajax function?
- wp_query for displaying attachments with a tag
- Multiple meta queries but arrange by specific meta value order
- Order Posts by meta value AND published date
- WP_Query with multiple meta fields filter?
- What format does the meta_query TIME type require?
- How to orderby meta_value_num with dollar ($) sign
- pre_get_posts order by not working
- WP_Query filter and order by meta ordering by wrong joined table
- WP_Query last five posts, simply ordered by meta_value
- Meta Query Array Error 500
- What is the random string I am seeing when I use get_query_var?
- Overwrite YoastSEO meta-tags with another page’s [closed]
- How to orderby multiple meta fields if some fields are empty
- Fetch Record based on meta key dates
- Suggestions on making this query/code more performant
- Where to put meta Keys
- Order by meta value (numeric value lower to higher)
- Large AND OR query timing out
- WP_Query with different postmeta filter for each categories
- meta_query not working as expected
- Slow WP_Query with ‘OR’ on meta_query
- How to filter a query by multiple meta keys and order by other meta keys
- Query posts with “non set” meta value
- Ordering a mysql style datetime stamp with meta_query
- Meta Query doesn’t works as espected
- Wp_query with 2 meta keys and array of meta values
- Advanced WP_Query with meta_query, orderby?
- meta_query: check if number exists
- Event with multiple dates, display events chronologically
- Display posts with specific value first in query
- WP_Query: apply an SQL function to meta fileld value
- How to search for meta_query LIKE or tax_query LIKE and grab these posts on search results?
- How to create dynamic value in WP_Query meta_query
- WP Query / Meta Query [duplicate]
- Query posts by searching for a string in a meta field
- WP_Query with 4 post meta field arguments gives 500 internal server error
- WP_Query: attachment image in “full” size?
- Use have_posts() with array of post results retrieved by $wpdb->get_results
- How can I build a query that returns all attachments of a page and it’s children pages?
- Query multiple post types, but different order for each
- How to add date_query to meta_query array
- Order by the first array within a meta_query
- Query ACF relationship field – Comparator IN – Value array
- Combine query in WP_User_Query()
- Multiple nested meta queries
- How to _GET multiple value checkbox WP_Query in Custom Toxonomy / Custom Fields
- What’s wrong with this meta query? (order by meta key, then title, doesn’t work)
- How can I modify the query by adding to the existing query?
- Meta query ignores multiple values of the key
- Multiple meta_query not returning rows
- WordPress Query custom ordering by temporary variable
- Check for not NULL not working in meta query
- Comparing Meta Field date in WPQuery using Meta_Query?
- Get unique post by meta value using wp_query
- How to create better WP_Query to look for date time which is anywhere between two meta values?
- Query against multiple locations within single custom post type post
- WP_Query, ACF field and array
- Order by Date Custom Field
- Filtering WP_Query based on wp_postmeta keys values
- Complex Meta Query
- Multiple meta_query not working
- compare for multiple meta values for same key in wp_query
- datetime picker, timestamps and meta queries
- WP_Query with meta_query won’t orderby
- meta_query only check if both value are set
- Get posts meta_query by repater field
- Query 3 meta_key and orderby
- wp_query sorting – one specific meta_key value at last and then sort by create date
- Extending WP Query: Custom geolocation meta values work, but tax_query breaks
- Using custom field as ‘orderby’ value causing post grouping by publish date
- Get closest event where meta_key field is an array
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- Set right order for query that returns posts based on two custom fields
- Meta_query weird behaviour
- Looking for a way to exclude frontpage and nav menu from query filter
- Creating Custom Query
- Get posts by meta value except one post [closed]
- WP_Query by meta key not returning any posts
- How do I have multiple metaqueries inside one wordpress query
- Display only posts with thumbnails