Considering WordPress Codex, and WordPress Template Hierarchy – attachments stores as post records.
Your code is making a loop redirection to the same page. The most reasonable case is:
Your $post->post_parent
equal to 0
. If you’ll make a var_dump(get_permalink($post->post_parent));
, youll notice that the output would be the same page url.
Related Posts:
- Programmatically adding images to the media library with wp_generate_attachment_metadata randomly fails
- Trying to hide buttons from Attachment window
- get_the_post_thumbnail() doesn’t taking style attribute
- Uploading Multiple Attachments From Front-End With A Description
- Validate alt text for attachments?
- complex restriction of items in media library
- Edit image / Delete image link
- How could I add button next to “edit image” button in “Attachment Details”
- Give attachments an archive page
- Insert Media – Attachment – Link to : Remove the “attachment page” option
- Can I attach a document (eg: PDF) but have a JPEG as a thumbnail?
- Retrieving a custom link on an attachment
- Delete attachments from Front end
- Creating a multi-file upload form on the front end for attachments
- get post attachments of a particular size
- How to upload image from front end and save in media library?
- attachment url rewrite
- How to create a CSV on the fly and send as an attachment using wp_mail?
- Get the title and URL of the attachment parent post
- Confused with attachment mimetype order
- query attachment images … if no attachments -> get attachments of parent page?
- Replacing with(out) regex link to attachment by links to files
- Getting attachment images is cloning some of them
- rename attachments based on parent-post-title on upload
- Rename attachments during upload no matter what filetype
- Link all WordPress images size
- Contact Form 7 Data As Attachment [closed]
- Post Via Email – How to send Attachments with it (e.g. PDF File or JPEG Image)?
- Displaying Post Attachment(s) at Top of single.php
- Detach an image from a page using php
- Get the path of the first attached media (single.php)
- custom admin thumbnail for videos, not getting post’s id?
- Custom Gallery HTML only working when images are attached to post/page
- Image Gallery Numbers for 3.5
- How do I link an image to the post it is attached to?
- How to delete a custom file from upload directory when deleting its post
- Open the Attachment Details popup
- Attachment page 404
- How to compress image before inserting to wordpress using wp_insert_attachment function?
- Query to only return the 2 newest post attachments (images)?
- How to update the title of audio file through its attachment metadata
- Change default selection for “Embed or Link”?
- How can I make an attachment page for pdf uploads?
- Proper use of wp_get_attachment_image?
- Redirect Attachment Page to Attachment
- Get title of post image is attached to
- the_time() returning wrong date/time (way in the future)
- Add audio attachment link to RSS
- Correct attachment size
- How to: Retrieve an attachment image from post and output it
- Remove attachment page for audio media type only
- Could not get attachment using wp_mail
- Looking to limit file attachment downloads
- Echo list attachment size in post
- How do I intercept and modify the functionality of wp_get_attachment_image()?
- Undoing define( ‘UPLOADS’, ”.’files’ ); to repoint to “wp-content/uploads” folder
- WordPress Gallery Permalink Structure Displaying Incorrectly
- Upload image and assign it’s id to post
- How to get thumbnail from post attachment in this loop
- i want attachment.php to return the image
- How can I rewrite old attachment URLs?
- How can I customize the link when an attached image is clicked?
- Add a word to the first // wp_get_attachment_url // as the subdomain name
- Change attached img anchor link to post link
- Media Library Mess After FTP … /uploads
- How to view exact image dimensions of a media in Admin view?
- wp_get_attachment_image_src calling wrong location
- wp_delete_attachment doesn’t delete image files / doesn’t work
- Get attachment URL from attachment Link in WordPress
- Removing images deleted from uploads folder, from Media Library
- How to open an attachment based on the date picker
- Send data URL string as an attachment in wp_email
- Display audio file in audio.php
- How to use previous/next image link, ignoring parent posts/attachments?
- how to add data in my custom theme from WP-Admin Panel
- Display setting ‘size’ not available in image settings modal
- Using $_FILES variable into the same function for uploading images and files
- Removing delete permanently button in uploading files media
- Retrieve ONLY mp3s and set a variable for use in a playlist called by single.php template?
- missing attachment are showing as 404
- Insert attachments from front end form
- How do I add Facebook OpenGraph meta tags for attachments in the header for a custom theme?
- Incomplete attachment page
- Drupal 6 to WordPress migration – media attachments
- How to retrieve “custom url” from image attachment in wordpress
- Retreive tags from attached post for media on page
- list of attachments: wp_get_attachment_link works, wp_get_attachment_image does not
- Custom attachment field dissapearing
- How can I let users access a specific attachment?
- What is the most efficient way to retrieve a group of image URL’s from different attachment ID’s of a specific crop size?
- How to wrap this Link with an Image?
- How to save media-form on custom tab
- get_image_tag filter not working
- Change attachment inside the_content using filters
- I want to edit documents on my blog without the need to download and upload files again [closed]
- Bulk delete media by year
- Count images in post then add class if just one
- One audio attachment, with two possible interchangeable extensions
- No attachments on contact form 7
- wp_mail attachment not working in wordpress