You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My Issue: I loaded several images in one post and thus they dynamically got assigned an attachment to that post. So when I erase the images from the post they still reflect in the gallery scroll depending on the number of items I call.
WordPress says
You can upload images in 2 places: Media page (uploads.php) or from Add Media button in a post/page edit page. When you upload images from the post edit screen, 'post_parent' for all images uploaded is set to current post. When you upload images from the Media page, 'post_parent' is set to 0.
When an image you have uploaded on media page is first inserted in the content of a post, or is included in a gallery inside the post, the 'post_parent' field is changed to the current post, just like it was uploaded using Add Media button of post edit screen.
As you noticed this does not happen for featured images, when an image uploaded on media page is used as featured image for a post, its post_parent stay unchanged.
Only thing that change is that a meta field '_thumbnail_id' is created for the post and its value is setted to the id of attachement post.
enter image description here
So if your post id is 10, get_post_meta(10, '_thumbnail_id', true); will return the ID of the post thumbnail.
Note that an image with post_parent setted to a post id does not mean that it's inserted in the content of the post, it can be uploaded using the post Add Media button, but never inserted in the post content.
Also the countrary is true, an image inserted in the content of a post can have a post_parent setted to another post id.
Plea
Is there a way to call only the images in the current published post editor?
The text was updated successfully, but these errors were encountered:
I found a plugin to help with this hack i.e unattach the featured images "Unattach and Re-attach Media Attachments". However doesn't help make the code more error proof.
Thanks for the theme Alex,
However while I was using it, I encountered one issue and it was in the
My Issue: I loaded several images in one post and thus they dynamically got assigned an attachment to that post. So when I erase the images from the post they still reflect in the gallery scroll depending on the number of items I call.
WordPress says
You can upload images in 2 places: Media page (uploads.php) or from Add Media button in a post/page edit page. When you upload images from the post edit screen, 'post_parent' for all images uploaded is set to current post. When you upload images from the Media page, 'post_parent' is set to 0.
When an image you have uploaded on media page is first inserted in the content of a post, or is included in a gallery inside the post, the 'post_parent' field is changed to the current post, just like it was uploaded using Add Media button of post edit screen.
As you noticed this does not happen for featured images, when an image uploaded on media page is used as featured image for a post, its post_parent stay unchanged.
Only thing that change is that a meta field '_thumbnail_id' is created for the post and its value is setted to the id of attachement post.
enter image description here
So if your post id is 10, get_post_meta(10, '_thumbnail_id', true); will return the ID of the post thumbnail.
Note that an image with post_parent setted to a post id does not mean that it's inserted in the content of the post, it can be uploaded using the post Add Media button, but never inserted in the post content.
Also the countrary is true, an image inserted in the content of a post can have a post_parent setted to another post id.
Plea
Is there a way to call only the images in the current published post editor?
The text was updated successfully, but these errors were encountered: