2014-09-25 64 views
0

在我的本地中,我可以使用以下代碼從帖子中獲取附加圖片。但在我的實時服務器中,$ images返回一個空數組。本地和現場會有什麼區別?我無法從Wordpress中的帖子獲取附加圖片

$images = get_children(
    array(
     'post_parent' => $post_id, 
     'post_status' => 'inherit', 
     'post_type' => 'attachment', 
     'post_mime_type' => 'image' 
     ) 
); 

感謝

+0

你確定圖像有post_parrent嗎? – 2014-09-25 01:45:55

+0

當我將圖像添加到帖子時,它們是不是會自動成爲該帖子的子項?你添加到文本編輯器(內容)的 – tolga 2014-09-25 01:47:35

+0

?或者你添加post_thumbnail? – 2014-09-25 01:49:53

回答

0

OK,我找到了答案.. 我得到的圖像與該代碼只有當我直接「上傳」圖片這一職務。

但仍然好奇,如果有一種方式來獲取插入到帖子(但在該帖子之前上傳)的圖像。

+0

檢查了這一點,從WP帖子獲取所有圖片:http://stackoverflow.com/questions/4081520/displaying-all-images-from-a-wordpress-post – tempranova 2014-09-25 04:18:35

+0

謝謝,但是,答案並不相同我正在嘗試使用的代碼? get_children具有相同的參數。我也嘗試get_post附件。 – tolga 2014-09-25 10:17:08

相關問題