0
我用下面的代碼來獲得所有附件分配給我的自定義後類型 ..但現在我想環路 ..how可以在得到這個職位ID 我這樣做?如何獲得張貼ID從附件WordPress的
$query = new WP_Query(
array(
'post_type' => 'portfolio', // adjust your custom post type name here
'posts_per_page' => -1,
'fields' => 'ids'
)
);
$image_query = new WP_Query(
array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'post_mime_type' => 'image',
'posts_per_page' => -1,
'post_parent__in' => $query->posts,
'order' => 'DESC'
)
);
if($image_query->have_posts()){
while($image_query->have_posts()) {
$image_query->the_post();
$imgurl = wp_get_attachment_url(get_the_ID());
if(!empty($output)) $output = 'Sorry, no attachments found.';
$output .= '<a href="'.$imgurl.'"><img src="'.$imgurl.'"></a>';
echo $output;
}
謝謝!
很好..工作..謝謝很多:) – jehan 2015-02-06 07:20:56
我的榮幸。享受:-) – 2015-02-06 07:21:26
只有一個小小的編輯,請看我的帖子,忘了添加單詞'parent' – 2015-02-06 07:22:52