【发布时间】:2017-07-23 08:59:19
【问题描述】:
我需要获取当前的分类术语 ID。我正在使用此代码。
$args = array(
'post_type' => 'property',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'property_category',
'field' => 'id',
'terms' => array( 84, 99, 98, 97, 92, 91, 95, 100, 87, 96, 94, 93 ),
'include_children' => false
)
)
);
正如您在“术语”部分中看到的,我创建了一个包含所有术语的数组,但我需要像当前页面术语 id 为 98 一样,我想仅在数组中设置 ID 98。
让我给你看一个例子: 此网址https://ayanaproperties.com/property-for-sale/london/ 的术语 ID 为 98,该术语仅显示 5 个正确的属性,但在地图部分地图上显示了所有 220 个属性。这是因为在上面的代码中,我在 terms 数组中指定了所有的 ID。
数组中的所有 ID 都使用相同的代码,这就是我需要 if else 条件的原因。
请帮帮我,我怎样才能使用 if else 条件?
谢谢,
【问题讨论】:
-
我认为您需要根据 term id 准备 terms 数组。不是吗?
-
显示你准备 $args 的代码
-
@JYoThI 我已经把php代码放在笔的js部分了,看这里:codepen.io/anon/pen/jLNjww
-
whats that id
$_POST['propcateg_id']为什么你不在你的 args 查询中使用它
标签: php arrays wordpress taxonomy taxonomy-terms