【发布时间】:2015-02-13 19:33:48
【问题描述】:
我正在页面模板上运行 wp_query,以便从自定义分类“位置”过滤的自定义帖子类型“游览”中获取帖子。这种分类法是分层和有组织的“土地 -> 地区 -> 地点”。使用相关模板的当前页面具有由 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'。 有没有办法找回这个?谢谢你的建议。
【问题讨论】:
-
$term_field = get_field('my_taxonomy', $post->ID);不成功? -
它给了我一个语法错误:解析错误:语法错误,意外的 T_STRING,在 /Applications/AMPPS/www/.../wp-content/themes/.../ 中期待 ')' template-leaflet-archive.php 在第 94 行。我正在尝试这样: 'tour', 'location' => '$term_field = get_field('spot', $后->ID);'); $featured_tour = new WP_Query($args); ?>
-
$term_field变量和声明不应在您的args数组中。location数组键需要是一个字符串值,这是您从 ACF 获得的字段。 -
如果我没听错的话,我不放心......你能告诉我使用什么代码吗?谢谢
-
<?php $your_tax = get_field('tax', $page_id); //$page_id should be the page of 'Meran' ?> <?php $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 税字段,您现在将获得它。
标签: advanced-custom-fields wordpress