Hi.

I have a single $tid and a constant node type that I'd like to use to get a list of nids that are tagged with that term and that match that node type.

I have been trying to use taxonomy_select_nodes() to do the first half of this, but have not been able to get what I want out of the code.

Can someone suggest a solution that yields a list of nids given the info I have?

Input: $tid, node_type = "nodetype"

Example Output: Array(14, 39, 72) OR loop that spits each NID out.

Thanks.

Erik.

Comments

joshk’s picture

Try something like

$result = db_query("SELECT nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE n.type = '%s' and td.tid = %d", $node_type, $tid);
while ($node = db_fetch_object($result)) {
  echo $node->nid;
}

------
Personal: Outlandish Josh
Professional: Chapter Three

------
Personal: Outlandish Josh
Professional: Pantheon

erikhopp’s picture

I appreciate it, as always!

for the record, here is some updated code with two fixed typos.

<?php
$result = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE n.type = '%s' and tn.tid = %d", $node_type, $tid);
while ($node = db_fetch_object($result)) {
  echo $node->nid;
}
?>

http://quilted.org

summit’s picture

Hi,
How to add the body/teaser to this please?
Thanks in advance for your reply!
Greetings,
Martijn

TapocoL’s picture

taxonomy_select_nodes

OR if you just want to display the node from the code used above, use the following:

$result = db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE n.type = '%s' and tn.tid = %d", $node_type, $tid);
while ($node = db_fetch_object($result)) {
  echo node_view(node_load($node->nid), TRUE);
}

This will load and display the teaser of every node selected from the previous query. Erase the 2nd argument of node_view ", TRUE" to display the body of every node selected.

-Craig Jackson
-Web Developer

summit’s picture

Hi Craig,
Thanks for the code. I am using it! Greetings, Martijn