我已经制作了一个自定义的帖子类型,称为“视频”,并在该帖子类型中,一个自定义类别称为“水晶”,同时使用这个插件(https://wordpress.org/plugins/video-thumbnails/生成的YouTube视频缩略图到帖子。
我试图通过所有的水晶帖子,只显示与永久链接到帖子的页面上的视频缩略图。
这是我的代码;
<div class="block" id="home-three">
<p>YouTube</p>
<?php
$args = array(
'post_type' => 'videos',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC',
'post_parent' => 0,
'tax_query' => 'crystal',
);
$count = 1;
?>
<?php $video_query = new WP_Query( $args ); ?>
<?php while ( $video_query->have_posts() ) : $video_query->the_post(); ?>
<div>
<a href="<?php the_permalink(); ?>">
<?php if( ( $video_thumbnail = get_video_thumbnail() ) != null ) { echo "<img src='https://wordpress.org/plugins/video-thumbnails/" . $video_thumbnail . "' />"; } ?>
</a>
</div>
<?php wp_reset_query(); ?>
</div>发布于 2015-10-16 00:40:48
根据documentation的说法,tax_query参数接受一个数组。
所以你的WP_Query参数应该是:
<?php
$args = array(
'post_type' => 'videos',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC',
'post_parent' => 0,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'crystal'
)
)
);
?> 您还可以使用Category Parameters
<?php
$args = array(
'post_type' => 'videos',
'post_status' => 'publish',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'DESC',
'post_parent' => 0,
'category_name' => 'crystal'
);
?> https://stackoverflow.com/questions/33153516
复制相似问题