[wp-trac] [WordPress Trac] #14247: Attachments programmatically added to Pages show a 404 error until Page is republished

WordPress Trac wp-trac at lists.automattic.com
Fri Jul 9 04:31:52 UTC 2010


#14247: Attachments programmatically added to Pages show a 404 error until Page is
republished
--------------------------+-------------------------------------------------
 Reporter:  bennebw       |       Owner:                 
     Type:  defect (bug)  |      Status:  new            
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Gallery       |     Version:  3.0            
 Severity:  normal        |    Keywords:  attachments    
--------------------------+-------------------------------------------------
 When adding attachments to Pages programmatically, they get the status
 'inherit', but viewing the Attachment Page returns a 404 error, even if
 parent Page is Published.  Republishing the parent Page fixes the problem
 for existing attachments, new ones will require republishing before they
 become active.

 This problem does not present when attaching to Posts, only Pages.

 It appears that Pages are not allowing attachments to be attached
 programmatically like Posts do.

 Background, this has been tested on 2 separate sites, and error is
 reproducible.  The situation is that images are being uploaded from the
 blog's front-end (so WP Media Uploader is not being used).  They are being
 attached to either Posts or Pages depending upon situation (Post
 attachments appear fine, Page attachments require republishing of parent
 page before attachments can be viewed).

 Here is the pertinent code being used for the upload:


 {{{
 $attach_id = wp_insert_attachment( $attachment, $file['file'],
 (int)$post_id );

 $attach_data = wp_generate_attachment_metadata( $attach_id, $file );

 wp_update_attachment_metadata( $attach_id, $attach_data );

 clean_post_cache( (int)$post_id ); //Added this trying to debug
 // Also tried wp_update_post() on parent_post, but it did not fix


 }}}

 Ultimately, this prevents the images from being used in a Gallery

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/14247>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list