似乎有几个类似问题的答案,但我还没有找到一个适合我的工作。从分类图库中获取图像
我有一个称为entertainement
的自定义后期类型。 entertainement
有一个分类标准ent_categories
。
其中ent_categories
被称为Event
每个Event
有一个画廊,我试图做一个查询,将返回已被添加到任何CPT entertainment
与Event
类别最新的10张图像。
我希望能得到一个数组中的URL列表。
从我读到这里这样的事应该做的伎俩:
$arg = array(
'post_status' => 'inherit',
'posts_per_page' => -1,
'post_type' => 'attachment',
);
$arg['tax_query'] = array(
array(
'taxonomy' => 'ent_categories',
'field' => 'name',
'terms' => array('Event'),
),
);
$the_query = new WP_Query($arg);
var_dump($the_query);
的var_dump($the_query);
显示了很多的东西,但没有图像? 关于这个的任何提示? 谢谢
编辑:
我刚才看到了,我可以这样做:在所有的画廊图片的网址都会显示在画廊下面的图片
function pw_show_gallery_image_urls($content) {
global $post;
// Only do this on singular items
if(! is_singular())
return $content;
// Make sure the post has a gallery in it
if(! has_shortcode($post->post_content, 'gallery'))
return $content;
// Retrieve all galleries of this post
$galleries = get_post_galleries_images($post);
$image_list = '<ul>';
// Loop through all galleries found
foreach($galleries as $gallery) {
// Loop through each image in each gallery
foreach($gallery as $image) {
$image_list .= '<li>' . $image . '</li>';
}
}
$image_list .= '</ul>';
// Append our image list to the content of our post
$content .= $image_list;
return $content;
}
add_filter('the_content', 'pw_show_gallery_image_urls');
这个结果。 也许这个功能可以从页面而不是从functions.php中调用?
你是什么意思_Each'Event'有一个gallery_?你的意思是ACF的画廊领域? –
谢谢你的回答。不,不是ACF galleryfield。使用“标准”wordpress图库作为简码添加图库 – eggman