0

私が作成した gallery_Category 分類内の猫 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 } ?>
4

1 に答える 1

1
<?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();
  } 

 } 
?>

これを試して

こちらも参考にしてください

wp クエリ

ワードプレスのループ

于 2013-10-01T16:00:58.527 に答える