【发布时间】:2020-07-20 16:55:45
【问题描述】:
我正在尝试使用从自定义字段中提取的变量来输入 tax_query 参数。然而什么都没有返回。我对我的变量做了一个 var_dump,它一直返回“boolean:False”。所以我想也许我需要运行一个循环(我的自定义字段是一个组的子字段),然后 var_dump 什么也不返回。我对 WP/PHP 开发相当陌生,不确定这里发生了什么。任何帮助将不胜感激!
<?php
if(have_rows('wine_profile')) :
while(have_rows('wine_profile')) : the_row();
$label = get_sub_field("taxonomy_label");
var_dump($label);
$wineProfiles = new WP_Query(array(
'posts_per_page' => '-1',
'post_type' => 'wines',
'tax_query' => array(
array(
'taxonomy' => 'labels',
'field' => 'slug',
'terms' => $label
)
),
'order' => 'DESC',
'orderby' => 'ID'
));
if ($wineProfiles->have_posts()) : while ($wineProfiles->have_posts()) : $wineProfiles->the_post();
get_template_part('includes/component', 'colorBlockLg');
get_template_part('includes/component', 'profile');
?>
<?php endwhile;
endif; endwhile; endif; ?>
【问题讨论】:
-
如果它返回 false,这意味着它没有找到任何东西。确保“taxonomy_label”是正确的名称。您也可以查看
var_dump('wine_profile')以了解其中的内容。 -
感谢卢克的回复。 'wine_profile' 是一个自定义字段组,所以我尝试了 $wine = get_field('wine_profile') 、 var_dump($wine) 并从中获取 'null'。
-
这很令人困惑,因为在 wp 管理员中我可以看到这些值,但它们没有被返回。
标签: php wordpress advanced-custom-fields custom-post-type