0

以下は、すべての投稿を表示するために使用しているワードプレスクエリですが、クエリは投稿のタグを表示していません。また、特定のカテゴリの投稿を表示するように次のクエリを変更する方法を教えてください。

<?php 
  $wp_query2 = null; 
  $wp_query2 =  new WP_Query(array(

 'post_type' => 'post',

 'post_status' => 'publish',
 'caller_get_posts'=> 0  ));

  while ($wp_query2->have_posts()) : $wp_query2->the_post(); 
?>

        <?php the_date(); ?>
        <br />
        <?php the_title(); ?>   
        <?php the_content(); ?>

<?php endwhile; ?>


<?php 
  wp_reset_query();
?>
4

1 に答える 1

0

あなたはこれを試すことができます

$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        'relation' => 'OR',
            array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => array( 'category1', 'category2' ) // replace these
            ),
            array(
                'taxonomy' => 'post_tag',
                    'field' => 'slug',
                    'terms' => array( 'tag1, tag2' ) // replace these
            )
    )
);

$query = new WP_Query( $args );
while ($query->have_posts()) : $query->the_post();
    // ...
    the_content();
    the_tags(); // display tags
endwhile;

WP Querythe_tagsを確認してください。

于 2013-09-19T17:46:17.157 に答える