2013-07-11 17 views
2

我不知道如何獲取附件的日期。我獲得的附件如下:WordPress的:如何獲得附件的日期?

$attachments = get_children(array('post_parent'=>$post->ID, 'post_type'=>'attachment', 'post_mime_type'=>'image')); 

foreach ($attachments as $attachment) { 
    //I want to get the date of the attachment 
} 

任何想法?感謝您的期待!

+0

我沒有運行WP的副本,但是您嘗試過[wp_get_attachment_metadata](http://codex.wordpress.org/Function_Reference/wp_get_attachment_metadata)嗎?我甚至不知道它會返回什麼,但在我看來它可能包含上傳日期。 – brbcoding

+0

如果你'print_r($ attachment)'它沒有包含發佈日期的字段嗎?如果是這樣的話,你應該'echo $ attachment-> pub_date'或者變量的名字。 – Djave

回答

2

附件是一種帖子,一天結束時的自定義帖子類型。因此,它們與其他帖子類型具有完全相同的表格和特徵。在評論@brbcoding的建議

foreach ($attachments as $attachment) { 
    echo $attachment->post_title . ' - ' . $attachment->post_date; 
} 

如果您需要特定附件的元數據,他們有專門的功能,如wp_get_attachment_metadata

這只是一個問題。