You want the permalink for the attachment’s parent post, so, if I am guessing correctly about the contents of $attachment
$parent_url = get_permalink($attachment->post_parent);
Related Posts:
- Remove subcategory slug from url
- How to allow WordPress to recognize a custom URL segment after a product URL and use a custom template?
- Getting 404 when using rewrite rule for posts
- Custom permalink structure only for default posts
- How to Group Posts by the First Letter or Number?
- Pretty URL with add_query_var
- get_permalink returns default link
- Why does rewrite rule work for page not for custom post type post?
- Dynamically generate child-URLs for posts or custom posts
- URL Rewriting if it is a single post / redirecting post – post type
- add_rewrite_rules for type of post
- Changing Permalinks for Default Post type to reflect navigation
- Custom Post Type – Category Rewrite – Remove Rewrite from Sitemap
- Duplicate Custom Post Type and Taxonomy Slug
- Visting slug for ‘post’ post type shows 404 not archive?
- Custom Post Type Rewrite To Include Parent Page(s)
- How do I Redirect a WordPress Page?
- Disable WordPress Archive Conflict Check
- $_GET parametters not working in an specific template
- Post-Archive like a page in a specific subdirectory
- Custom Post Type, post-formats associated to custom post type > 404 archives
- add_rewrite_rule and template redirect not working
- Add static text to post URLs
- My post permalinks are redirecting to the post archive page for some reason?
- How to add a ‘News’ section to specific posts in WordPress
- Add a url parameter to the current post and read it in a shortcode
- Prevent Archive URLs
- Slug collision between page, taxonomy and custom post type
- How to add category base prefix to wordpress permalink
- Multipage Post URL correction
- Fixing the WP Post Object for Custom Route
- Posts in Page – How to customize the URL?
- Use a custom post URL that is outside the blog root directory
- Rewrite a specific Post Format to URL slug
- Overwrite URL on blog posts
- Blog posts are not appearing as subs of Blog Page
- How to change url of posts?
- Post pages are redirecting to the 404 page in wordpress
- Add tag to post api wordpress
- Confirmation box when submitting post for review
- How to show list of posts by author and category?
- Removing taxonomy base using WP rewrite
- how to limit and display tag?
- Insert custom div between posts
- How to Display Post View Count
- Remove double space after a period
- Adding Multiple Values to a Post Meta Key
- Displaying the number of posts in a custom loop (without including the number of posts of a loop below)?
- display order of connections
- How to do Basic URL Rewrite Without Redirecting
- Warning: Creating default object from empty value in … /post.php
- Display page content AFTER a loop of posts
- How to get the date of a post in WordPress, so I could use it in a script?
- Unwanted Duplicate Posts Showing in Pagination Pages
- Downgrade user from role that allows post creation
- How to store an extra (surrogate) ID when creating a post with wp_insert_post?
- Batch process: remove first image from post content
- Articles are text-only in any “Category” instead of HTML
- Delete WordPress posts from URL list sql query
- Posts with multiple authors with different roles
- How to get the user meta data for a post?
- Auto insert More tags in all posts
- How to change post status from frontend?
- How to get next post ID?
- How to display content from the main blog on another from multisite network as it would be its own
- Create custom permalinks to show Custom Post Type’s relationship?
- Display an author’s posts on his own author page
- Static posts page with home.php
- A/B testing of posts with unique URLs for each variant AND editing in custom fields
- Using setup_postdata() with multi-dimensional array
- Post Form Results to Table in Same page
- Post Title to featured Image ALT
- wp_query if have posts show date but not in loop
- Send email to admin with post author
- posts going to 2 pages/categories only show up in 1
- Custom post type change permalink query
- Older blog posts not showing up on WordPress
- wp-insert-post execute from server?
- Embedding Post Editor Into External Site
- WordPress rewrite rule depend on meta values not ids
- Send email to user when I publish a new post
- Pagination Stops
- How to mark only one post as Featured post?
- Remove status ‘archived’ from the default post and page view
- Custom Post Types and Broken Permalinks
- Allow registering user to select post category when signing up to blog
- how to call recent post content in a loop ( only the content before read more tag)
- How can I filter the post of a CPT by taxonomy Term in admin meta-box dropdown?
- Show Posts By Custom Field
- Back up post tags
- form to post multiple inputs into post_content
- How can i add new post on new page
- Custom Taxonomy in Permalink from post type
- how to style an individual page in a category [duplicate]
- Post thumbnail height problem
- get_posts includes “auto drafts”?
- how to add single wordpress post to multiple wp category with different different title
- Hide post title when single post with specific category
- How to automatically convert a form with HTML link into post
- WordPress Post Updating is Not Working