如何从tid中获取nid,这样我就可以使用node_load函数,然后使用Field_get_items来获取特定的字段。我首先使用了taxonomy_select_node(),但它提供了与该tid相关的所有节点的nids,但我需要特定包(内容类型)的nids,因此我只能显示该内容类型的内容。现在我正在使用Entityfieldquery,下面是我的代码:
if(isset($_GET['tid'])){ $id=($_GET['tid']); $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'node'); $query->entityCondition('bundle', 'escorts_product'); $query->propertyCondition('status', 1); $query->fieldCondition('field_description', NULL, $id, '='); $result = $query->execute(); print "<pre>";print_r($result);
这里,我想从我的内容类型escorts_product中获取特定$id=tid的field_description,但它给出了所有tids的数组结构,而不是我在参数中提到的特定tids的数组结构?
发布于 2015-03-14 14:40:52
$query->fieldCondition('field_description', NULL, $id, '=');
应该像这样替换行,它将会工作,
$query->fieldCondition('field_your_term_reference_field', tid, $id, '=');
然后你就可以很容易地获得nid了。
发布于 2017-01-19 20:21:56
这对我很管用
$termid = array(1); //Where you save term ID(s)
$nids = taxonomy_select_nodes($termid);
$products = array(); //Lets say nodes type is PRODUCT
if (!empty($nids)) {
foreach ($nids as $nid => $value) {
echo $products[$value] = node_load($value)->title; // Echo all the titles of related nodes of current term.
}
}https://stackoverflow.com/questions/29045885
复制相似问题