[wp-trac] [WordPress Trac] #30691: Removing a featured image does not remove the 'post_parent' value - reproducible

WordPress Trac noreply at wordpress.org
Fri Dec 12 12:38:50 UTC 2014


#30691: Removing a featured image does not remove the 'post_parent' value -
reproducible
--------------------------+-----------------------------
 Reporter:  juggledad     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.0.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Removing a featured image does not remove the 'post_parent' value in the
 wp_posts row associated with the attachment. This causes invalid results
 when using functions like get_children() and get_posts().


 1) install a fresh copy of WordPress 4.0.1
 2) edit the first post and add a featured image
 3) use phpMyAdmin and look at the wp_posts table. You will see an entry
 for the attachment and the 'post_parent' column will be set to the ID of
 the first post
 4) Edit the first post and remove the featured image
 5) again use phpMyAdmin and look at the wp_posts table. You will see the
 entry for the attachment and the 'post_parent' column WILL STILL BE SET to
 the ID of the first post.

 to see a example of an error with get_children() do the following after
 doing the above.
 1) activate twenty-thirteen and view the site
 2) edit twenty-thirteen's 'content.php'. Line 15-19 should be


 {{{
                 <?php if ( has_post_thumbnail() && !
 post_password_required() && ! is_attachment() ) : ?>
                 <div class="entry-thumbnail">
                         <?php the_post_thumbnail(); ?>
                 </div>
                 <?php endif; ?>

 }}}

 add the following right after it.


 {{{
 <?php
         $args = array( 'post_type' => 'attachment', 'numberposts' => -1,
 'post_status' => null, 'post_parent' => $post->ID );
         $attachments = get_posts($args);
         if (! empty($attachments)) {
                 echo 'attachment ID ='.$attachments[0]->ID.'<br>';
                 echo 'attachment post_parent
 ='.$attachments[0]->post_parent.'<br>';
                 echo '$post->ID ='.$post->ID.'<br>';
         echo '<img src="' . $attachments[0]->guid . '"/>';
                 var_dump($attachments);
         }
 ?>

 }}}

 3) view the site and you will see the featured image.
 4) use phpMyAdmin edit the entry for the attachment and set the
 'post_parent' column to '0'.
 5) view the site and you will NOT see the featured image.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30691>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list