WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#26812 closed defect (bug) (worksforme)

Unable to get attachment information in post or page .

Reported by: phpgenie Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8
Component: Media Keywords: 2nd-opinion
Focuses: Cc:
PR Number:

Description (last modified by ocean90)

Hello Sir

I am explaining this issue step by step.

  1. Create new post or page.
  2. Upload few images and few videos.
  3. Insert 1 image and 1 video.
  4. Publish this post.
  5. Edit this post and insert another video and image.
  6. Update this post.

Now on front end, index.php page I want to show attachment information associated with images, videos like title, description. I am using following code inside loop.

<?php 

$mchilds =& get_children( array (
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => 'any',
 ));

//print_r($mchilds);
?>

Resulting array $mchilds contains info about only one attachment. I have inserted 2 images and 2 videos, but $mchilds array is containing info of first one only.
When I checked the database and run this query in database "select * from wplr_posts where post_parent='111'" then I found that other 3 attachments have value "revision" for "post_type" column.
If I changed value of "post_type" column manually to "attachment" then in front end I will get info about all attachments in $mchilds array.

I have checked this with 2 themes present in wordpress, I requested my brother also to check this and he also informed me same.

So, I have a request, Please consider this issue.

Thanks for your time.

Regards
Nidhi

Change History (5)

#1 @ocean90
6 years ago

  • Description modified (diff)

#2 @UmeshSingla
6 years ago

I couldn't replicate the issue, instead of using get_the_id() ( as it would have fetched my all posts, not inside loop ), I used the actual post id, and it works fine.

Last edited 6 years ago by UmeshSingla (previous) (diff)

#3 @bcworkz
6 years ago

Could not replicate either. My attachments remained attachments. The only posts rows that became revision were the post auto-save rows. I have no media rows that are post_type revision. It should not happen AFAICT.

#4 @UmeshSingla
6 years ago

  • Keywords 2nd-opinion added
  • Resolution set to invalid
  • Status changed from new to closed

#5 @ocean90
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution changed from invalid to worksforme
Note: See TracTickets for help on using tickets.