【问题标题】:Wordpress Display Post Tags and by CategoryWordpress 显示帖子标签和按类别
【发布时间】:2013-09-20 01:51:57
【问题描述】:

以下是我用来显示所有帖子的 wordpress 查询,但查询不显示帖子的标签,还请告诉我如何修改以下查询,以便显示来自任何特定类别的帖子。

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

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    你可以试试这个

    $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

    【讨论】:

      猜你喜欢
      • 2017-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多