wordpress - Image post attachments not specific to post -


my issue: loaded several images in 1 post , dynamically got assigned attachment post. when erase images post still reflect in gallery scroll depending on number of items call.

this code calling attachments

function sunset_get_attachment($num = 1) {    $output = '';    if (has_post_thumbnail() && $num == 1):         $output = wp_get_attachment_url(get_post_thumbnail_id(get_the_id())); else:         $attachments = get_posts(array(            'post_type' => 'attachment',             'posts_per_page' => $num,             'post_parent' => get_the_id(),         ));     if ($attachments && $num == 1):             foreach ($attachments $attachment):                 $output = wp_get_attachment_url($attachment->id);     endforeach; elseif ($attachments && $num > 1):             $output = $attachments;     endif;     wp_reset_postdata();     endif;     return $output; } 

wordpress says can upload images in 2 places: media page (uploads.php) or add media button in post/page edit page. when upload images post edit screen, 'post_parent' images uploaded set current post. when upload images media page, 'post_parent' set 0.

when image have uploaded on media page first inserted in content of post, or included in gallery inside post, 'post_parent' field changed current post, uploaded using add media button of post edit screen.

as noticed not happen featured images, when image uploaded on media page used featured image post, post_parent stay unchanged.

only thing change meta field '_thumbnail_id' created post , value setted id of attachement post.

enter image description here

so if post id 10, get_post_meta(10, '_thumbnail_id', true); return id of post thumbnail.

note image post_parent setted post id not mean it's inserted in content of post, can uploaded using post add media button, never inserted in post content.

also countrary true, image inserted in content of post can have post_parent setted post id.

plea there way call images in current published post editor?

instead of trying code around it, simpler detach image post uploaded to. can in media library:

  1. make sure in list view , "uploaded to" column showing
  2. there "detach" link in "uploaded to" column under post name - clicking break association between , post uploaded to.

fyi, "attach" link shown images not associated post, if detach image mistake can use reattach it.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -