You’ll need to first grab the posts, then grab the attachments that are children of said posts.
$my_query = new WP_Query( array(
'meta_key' => 'my_hash',
'nopaging' => true,
'orderby' => 'meta_value',
'fields' => 'ids',
'cat' => '60',
));
if ( $post_ids = $my_query->get_posts() ) {
$post_ids = implode( ',', $post_ids );
$atts_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_parent IN($post_ids) AND post_type="attachment"" );
$my_query->query( array(
'posts_per_page' => $batch_size,
'post_mime_type' =>'image',
'post_status' => 'all',
'post_type' => 'attachment',
'post__in' => $atts_ids,
));
}
Related Posts:
- Get all categories and posts in those categories
- Combine two taxonomies in a hierarchical tree
- How to get posts from two categories with WP_Query?
- Group WP_Query by category
- Exclude categories from search query
- How can I reduce the number of database query calls for this custom homepage?
- WP_Query not looking at child category
- Get page content by category or tag
- Excluding posts from a category but only if they’re not in multiple categories
- What could be causing my wp_query pagination to break?
- Custom query with category exclusion and post-meta “whitelist”
- Exclude most recent posts from specific category in wp_query()
- Display one latest post from multiple categories
- How to Check if a Child Category is Being Queried
- Attachment page per category
- How to query posts from specific authors and categories using WP_query?
- How to show in search results posts with a particular tag in a particular category?
- Custom WP_Query for current category (in category.php)?
- List Posts by Category for a Non-Zero, Non-NULL Custom Field Value?
- getting content from main domain to sub-domain using category and WP_Query
- Set the default category of an attachment
- WP_Query() returns null when results exist!
- Ignoring a category in WP_Query still shows the links in next_post_link()?
- 3 Columns, 3 Categories, One Archive, and Pagination
- Enter a variable in the ‘category_name’ parameter
- How to query post like normal search would do. within search.php page
- Link Attachment Image to Category
- Remove product category placeholder image (Woocomerce)
- Multiple Loops on category.php with pagination on last loop
- How to limit number of attachments
- How to get latest posts from each category in regular order
- change recent posts based on category
- How to remove specific categories from posts?
- get_post_meta not working on category.php
- Set colors depending on category
- Display posts from a category
- Custom loop of a single category, cannot order by date. What am I missing?
- Pagination on category.php and tag.php not working
- category__not_in and id values from variable
- Use premade array as categories in wp_query?
- WP_Query – using category__and when one of the categories is 0
- More efficient way to list posts by category [duplicate]
- Adding a block with query in homepage
- Query posts by views on category page
- Change categories count to include media attachments
- I need to exclude from a query a category and a few custom taxonomies
- Show multiple categories in query using redux framework variable
- Are term_taxonomy_id and term_id the same? [duplicate]
- Return category posts with WP_Query
- Using in ‘category_name’ in ‘$query->set();’?
- multiple values in an array for category__and does not work with WP_Query
- Custom Page Template Category loop not functioning correctly
- Retrieve post tags from from main wp_query
- Posts of specific category on page and excluded from index.htm
- new WP_Query issues
- How can I use AJAX with check-box categories?
- Select posts that match multiple category names, must match all categories listed
- the_category() doesn’t working in wp_query loop
- How to display the 5 latest post titles but allow only 1 in there of a specific category
- Multiple if statements with else for get_the_category [closed]
- How get all media from a posts category by db?
- Unable to get all tags from specific categories
- category__and works, but why?
- foreach,having wp_query inside, breaks after showing one result
- Display related posts with same category or same tag return blank
- $args Orderby The number
- Querying Multiple Categories With Different Offsets
- WordPress Numeric Pagination with Query String [duplicate]
- Printing direct descendants of a category with WP_Query
- Custom Category Page Not Working [duplicate]
- WP_query exclude a category unless it has more than one catagory
- Show only one category in main query, issues on tag page
- Multiple Categories under one URL, where ‘Front Page’ is used already
- How do i add custom post types to this query?
- Narrow Down a Shop Page Results Based on a Product Tag in WooCommerce
- How to retrieve posts from parent category, splitting them per children when displayed?
- How to link images of one WP site to another WP site?
- Trying to WP_Query a category
- How to show posts of an columnized different categories on the same line or row?
- Echo one category as title when post has multiple categories?
- I use same slug name for category and page
- On Category page, How can I get the category ID?
- How do I display the posts from a custom post type on a category.php page?
- How do I call posts with a certain tag?
- Get URL Category Name By ID
- Show parent categories and sub categories but not grand children categories
- WP_Query with one category in args shows other categories
- Why is my sub-category template showing the wrong posts
- Sidebar limiting to 10 posts?
- Natural sort / ordering wp_dropdown_categories
- Best way to categorize/populate a magazine style layout
- Mass Update User Profile Checkbox Options
- Category sticky latest
- How to list posts from a sub-category that is listed in a parent category (more details below)?
- Query prints posts without specific categories
- In ACF, how to show custom category selection tab upon selecting a main category
- WooCommerce – Get products from category right before deleting category
- Category For Pages In WordPress
- Inserting categories as a hierarchical terms from frontend form
- Display post of current parent category, and in right hand side show child category post