Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress从自定义分类检索帖子_Php_Wordpress_Taxonomy - Fatal编程技术网

Php Wordpress从自定义分类检索帖子

Php Wordpress从自定义分类检索帖子,php,wordpress,taxonomy,Php,Wordpress,Taxonomy,我正在尝试加载我创建的gallery_类别分类中第5类帖子中的所有图像。什么都没用,我不明白为什么不行 <?php $args = array( 'post_type' => 'post', 'taxonomy' => 'gallery_category', 'term_id' => '5' );

我正在尝试加载我创建的gallery_类别分类中第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();
  } 

 } 
?>