All media (somewhat incorrectly) in the $wpdb->posts
table will be “attachments” whether actually attached or not. “Attachments” that are actually attached will have a post_parent
other than 0, so what you need are all of the attachments that have a 0 in the post_parent
column, if I understand you.
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'posts_per_page' => -1,
'post_parent__not_in' = array(0)
);
$attachment = new WP_Query($args);
var_dump($attachment->posts);
Related Posts:
- Exclude post ID from wp_query
- Broken? WP_Query and “attachment” as a post type
- Is it possible to query all posts that don’t have an attachment?
- How to paginate wordpress [gallery] shortcode?
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- Getting attachments by meta value
- Count the number of images uploded on the website
- How to paginate attachments in a secondary query as gallery?
- How do I exclude all images from a wp_query?
- How to filter by category in REST API, excluding posts also in other category term?
- get images attached to post
- query attachments of parent page if attachments of current page are smaller than …
- Query Ignoring ‘exclude’ Parameter?
- wp_query for displaying attachments with a tag
- Show selected images on top in Media Manager
- How can I query posts with newly uploaded images?
- Sorting By Custom Posts With Attachments
- WP_Query Excluding pages with Order is 0
- Attachment changing page’s permalink – $post not resetting?
- Query: offset post list, unless it’s a specific category
- How to fetch only media that was already attached to a post/page?
- How to do meta_query for attachments?
- Get attachment by meta_key value
- How to show optimized list of posts with all their attachment images
- Where to put meta Keys
- Excluding pages in WP_query using ACF
- Exclude Category filter from Portfolio section
- Avoid repeated post on page 2 when excluding one on page 1
- WP_Query Attachment adds additional attachment count and need to link attachment to post url
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- Include posts from some categories while excluding from others
- Exclude current post from an array of posts?
- Exclude recently updated post from custom WP_Query using multiple loops
- How to exclude Sticky from Recent Post?
- Why having more than 10 clauses in WP_Query results in some outputs being dropped?
- wp_query get attachments in larger size
- Creating attachments archive in tags and categories
- Ignore image urls in wp_query search
- specific post is not excluded from the loop
- WP_Query: attachment image in “full” size?
- How can I build a query that returns all attachments of a page and it’s children pages?
- get all images from the wordpress media library with link to the post they are associated with
- How to restrict add media library only to images of the same post family?
- how to get custom attachment url?
- wp_get_attachment_image not to get the post_thumbnaill
- Query All Attachments and Order by Parent Publish Date
- How To Query All Attachment Images Found In Post Galleries
- WP_Query for attachments without duplicating post_parent and displaying tagged image
- Using WP_Query to get attachment returns empty set
- Some images not being returned with wp_get_attachment_image
- Loop issues when creating custom query for media uploader
- Paginate wp_query while utilizing post__not_in
- WP Query Obj: Set value to be unequal | Hide media by admin
- Give attachments an archive page, and exclude unattached ones
- on attachment.php, how to display previous and next attachment links that follow the same order as a custom WP Query
- order by numeric value for meta value
- numberposts? showposts? posts_per_page?
- $GLOBALS[‘wp_the_query’] vs global $wp_query
- How to query posts based on lat-lng coordinate as post meta?
- How to query only for products with status “in stock” in WooCommerce? [closed]
- WP_Query displaying ALL posts
- Does WordPress sanitize arguments to WP_Query?
- How to combine tax_query and date_query in WordPress
- How to order posts in wp_query by a meta_value of the corresponding author
- How to get sum of meta_values of a meta_key in wp_query according to conditions
- Get the post thumbnail with wp_query
- Where to use $post global variable?
- Multiple instances of Featured Image Query
- WPDB query – decrypting DB data
- Storing query variable and then using wp_reset_query
- exclude posts with a specific custom field and value
- Redirect page when URL parameter not set
- Moving the array pointer inside a WP_Query while loop
- Query posts(CPT, pages , hierarchical) by Ancestor ID
- Input check to custom post type query
- Get a list of posts with associated meta_value
- Query post with meta value in set of values
- get_template_part causes 500 error
- Get posts in taxonomy randomly
- Max Posts and Memory Limit
- WP_Query orderby
- Using Ajax and WP_Query to load more posts on category page fails
- I have problems with the search query using multiple post types
- How to check if logged in user have pending custom post?
- Different query result on local and server
- How can I show only last year posts in wordpress archive?
- Change database image location for transportability
- Combine Tax Archive and Meta_Query in WP_Query
- Get posts by birthday
- How to add in WP_Query to every 3 posts displayed? [duplicate]
- how to avoid reloading/refresh the page when displaying the post of wp_list_categories
- Pagination not working with WP_QUERY
- Custom Content Slider stop duplicate
- Sort Posts with custom meta key by default which is currently set as optional
- wp_query pagination links producing 404
- Pagination problem with multiple loops on the same page
- Carousel slider with WP_Query to show 3 posts on each slide
- how to use transient method?
- WP_Query – meta fields numeric
- How to query posts from single post format on Genesis framework