通过动态标签和帖子类型发布帖子

时间:2016-06-10 16:35:17

标签: wordpress dynamic tags

我有一个名为spotlight的自定义帖子类型。我试图从帖子类型的帖子中找到标记相同标签的帖子,无论聚光灯被标记。这是我的工作代码。有人可以指点我正确的方向吗?

function special_loop() { 
$posttags = get_the_tags();
if ($posttags) {
  foreach($posttags as $tag) {
    echo $tag->name . ' '; 
  }
}
$q = new WP_Query(array(
    'posts_per_page' => 6,
    'post_type'=>'post',
    'orderby' => 'date',
    'order'   => 'DESC',
    'tag' => '$posttags = get_the_tags();',
));

if($q->have_posts()) : while($q->have_posts()) : $q->the_post();
    do_action( 'genesis_entry_header' );
endwhile;endif;
}

1 个答案:

答案 0 :(得分:0)

我认为我有这个:

function special_loop() { 
$posttags = get_the_tags();
if ($posttags) {
  foreach($posttags as $tag) {
    //echo $tag->name . ' '; 
      $spotlighttag = $tag->name;
      echo $spotlighttag;
  }
}
$q = new WP_Query(array(
    'tag_slug__in' => array( $spotlighttag), 
    'posts_per_page' => 6,
    'post_type'=>'post',
    'orderby' => 'date',
    'order'   => 'DESC',
));

if($q->have_posts()) : while($q->have_posts()) : $q->the_post();
    do_action( 'genesis_entry_header' );
    echo 'this at least go here';
endwhile;endif; 
wp_reset_postdata();
}