使用ACF分类法字段术语作为wp_query的值

时间:2014-12-15 16:26:27

标签: wordpress advanced-custom-fields wp-query

我在页面模板上运行wp_query,以便从自定义帖子类型中获取帖子" tour"通过自定义分类法" location"进行过滤。这种分类法是分层的,有组织的" land - >地区 - >点&#34 ;.使用相关模板的当前页面具有由ACF分类法字段分配的相同分类。这个wp_query实际上工作正常:

<?php $args = array( 'post_type' => 'tour', 'location' => 'meran' ); $featured_tour = new WP_Query( $args ); ?>
<?php if ( $featured_tour->have_posts() ) : while ( $featured_tour->have_posts() ) :     $featured_tour->the_post(); ?>
    <article>
        <h1><?php echo get_the_title(); ?></h1>
    </article>
<?php endwhile; else : ?>
    <p>No tour here! :( </p>
<?php endif; wp_reset_postdata(); ?>

我现在想用在ACF&#34; spot&#34;中选择的术语替换该位置的名称。领域,例如:&#39; location&#39; =&GT; &#39; function_that_inserts_current_ACF_term&#39 ;. 有没有办法检索这个?谢谢你的任何建议。

1 个答案:

答案 0 :(得分:1)

    <?php $your_tax = get_field('tax', $page_id); //$page_id should be the page of 'Meran'
$args = array( 'post_type' => 'tour', 'location' => $your_tax );

 $featured_tour = new WP_Query( $args ); ?> 

<?php if ( $featured_tour->have_posts() ) :
 while ( $featured_tour->have_posts() ) : $featured_tour->the_post(); ?> 
<article> 
   <h1><?php echo get_the_title(); ?></h1> 
</article> 
<?php endwhile; 
else : ?>
  <p>No tour here! :( </p> <?php endif; wp_reset_postdata(); ?> 

如果当前页面中存在ACF税收字段,您现在正在获取该字段。

相关问题