get_post_ancestors
can give you the ID of the object an attachment is associated with:
$attachment_id = 42;
$parent = get_post_ancestors( $attachment_id );
echo $parent[0]; // $parent will be an array
Related Posts:
- Turn a URL into an Attachment / Post ID
- Delete Associated Media Upon Page Deletion
- Delete post with all files attached to it
- Is it possible to Schedule Attachments in WordPress?
- what types of order can I pass to get_posts() via orderby?
- Find the post an attachment is attached to
- media_handle_upload for local files?
- How do I detach images from posts?
- Use an attachment in multiple posts
- delete post also attachments
- Replacing all attachment links in post with media file link
- How can I export WordPress posts’ attachments?
- How to remove images from showing in a post with the_content()?
- How do I create Comma Separated list of attached image ids?
- Get post embedded image caption
- Limit amount of results returned
- post_parent is 0 when uploading new files
- Easy way to delete 70k posts and attached media?
- How to access featured image?
- Load post attached images on a single page site with fancybox
- Insert woocommerce products programmatically with featured image and gallery
- Add the description field on the attached media
- Set size for attachments
- I have a site where attachments in the wp_posts table have guid values of guid, how did this happen?
- Get all attachment by post excluding featured and content inside
- Prevent Delete Attachment by URL or When Submit
- Posts and Attachments with “Published” status in Search
- Get attachments for posts that belongs to a specific category
- Automatically attach image to post if they have the same title
- Get Image tag from content of post
- Can’t update old posts 3.5.2
- How would one change the default url structure of attachments?
- Get attachments only for this post
- Upload attachment from external site
- Reinstall WordPress while keeping attachments
- Get images from the post
- How To Download WordPress Audio Attachments
- How to get the next and previous image title from attachment or gallery?
- All images on one line for each post
- How do I assign an attachment to a post using only the REST API?
- Unable to delete attached file from folder programmatically
- How to convert attachment pages to Posts?
- Get post attachment with post id
- Delete attached images from posts
- Unable to get all the Posts Attachments
- Add in the url attachment loop the wp_link_pages of the post
- Stop images from being displayed on the front-end of the site
- How to get images only attached from edit post page
- How to prevent people from seeing an attachment to a scheduled post that’s released in future?
- How can I get a comment ID on Submit?
- Bulk Attach Or Insert Media To Post Without Opening Post Editor
- Post Attachment missing head (stylesheets/js/what-not)
- Create post from form with image
- Get Video Attachment to post
- how to edit attachments?
- Broken images after importing posts and opening in Gutenberg
- Is post ID number always incremental n+
- post__in for get_posts with a dynamic array
- Why do I need to use The Loop on pages (inside page.php etc)?
- How to get previous 10 days post from a specific date – WP Query
- Automatically added brs and paragraphs?
- Allowing a user to write a post from another website?
- Delete Post Link to delete post, its meta and attachments
- prevent showing posts of an specific category in admin posts section
- New blog template to display only one category
- wp_insert_post question [closed]
- publish_post conflicts with save_post
- WordPress list posts from sub categories
- Dynamically generate child-URLs for posts or custom posts
- Format the Layout of Images In The Edit Post Textarea?
- Get Posts Under Custom Taxonomy
- how do i add posts-page slug before posts slug in permalinks
- wp_query random post
- Hide posts belongs to few categories in homepage
- Every second post different class in blog view
- Is codex right on deleting post?
- WP text styles not coming through to actual post
- WordPress post page not working properly
- Changing Post Tag Color Based On Post Count
- Programatically adding custom filters to post list
- Is it possible to automatically publish a post once a woo-commerce product is published?
- Post is blank when I click on the link
- Retrieve post in AJAX Callback
- Get postlist for each category using query_posts?
- Why does WordPress search returns same number of results for every search query?
- links to posts not working on homepage
- Posts and order
- Nest Next and Previous in a href with class that has a background image
- Override WordPress core post-template.php block template
- Count singular post views automatically
- Pagination (on the static front page) shows always the same posts
- Loop and output 4 rows of posts on home page
- Loop through all posts showing duplicates
- Code works on a page but not in a widget
- Make a paginated article (for easier reading on mobile)
- WordPress post text starts newline after 93 characters
- Deleling wordpress posts permanently still have IDs
- wp trim function not working
- Import alt text in set_post_thumbnail
- WordPress Post Updating is Not Working