首页 文章

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

提问于
浏览
0

我正在页面模板上运行wp_query,以便从自定义分类“location”过滤的自定义帖子类型“tour”中获取帖子 . 这种分类法是分层的,有组织的“土地 - >地区 - >现场” . 使用相关模板的当前页面具有由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“spot”字段中选择的术语替换该位置的名称,例如:'location'=>'function_that_inserts_current_ACF_term' . 有没有办法检索这个?谢谢你的任何建议 .

1 回答

  • 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税收字段 .

相关问题