Php Wordpress从自定义分类检索帖子
我正在尝试加载我创建的gallery_类别分类中第5类帖子中的所有图像。什么都没用,我不明白为什么不行Php Wordpress从自定义分类检索帖子,php,wordpress,taxonomy,Php,Wordpress,Taxonomy,我正在尝试加载我创建的gallery_类别分类中第5类帖子中的所有图像。什么都没用,我不明白为什么不行 <?php $args = array( 'post_type' => 'post', 'taxonomy' => 'gallery_category', 'term_id' => '5' );
<?php
$args = array(
'post_type' => 'post',
'taxonomy' => 'gallery_category',
'term_id' => '5'
);
$query = new WP_Query($args);
while ($wp_query->have_posts()) {
$wp_query->the_post();
?>
<?php the_post_thumbnail(); ?>
<?php } ?>
试试这个
也请参阅此处
<?php
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'gallery_category',
'field' => 'slug',
'terms' => '5'
)
)
);
$my_query = new WP_Query($args);
while ($my_query->have_posts()) {
$my_query->the_post();
if ( has_post_thumbnail()) {
the_post_thumbnail();
}
}
?>