Hey I'm modifying the Upcoming Events block so that it only shows content from a select Taxonomy.

This is the original code
$result = db_query_range("SELECT n.nid, n.title, n.status, n.moderate, e.* FROM {node} n ". node_access_join_sql() ." INNER JOIN {event} e ON n.nid = e.nid WHERE n.type='event' AND ". node_access_where_sql() ." AND n.status = 1 AND e.start >= $time ORDER BY e.start",0,$limit);

I tried modifying by adding another JOIN to query the taxonomy table, but there is a flaw in my MYSQL.

$result = db_query_range("SELECT n.nid, n.title, n.status, n.moderate, e.*, t.id FROM {node} n ". node_access_join_sql() ." INNER JOIN {event} e ON n.nid =e.nid JOIN {term_node} t ON n.nid=t.nid WHERE t.tid='2' AND n.type='event' AND ". node_access_where_sql() ." AND n.status = 1 AND e.start >= $time ORDER BY e.
start",0,$limit);

I was just hoping that someone could rewrite it so that it worked, or tell me a better way to go about it.
I would like to write a function that would allow the administrator to create blocks to go with different taxonomy categories, but I don't know how I'd go about it, perhaps I can learn enough by tinkering to figure it out. Thanks for any help.

Comments

veridicus’s picture

I haven't scrutinized every part of your SQL, but you're missing the INNER keyword before the JOIN you added. At least I assume you mean an inner join. Use LEFT OUTER JOIN if you also want the nodes not tied to any taxonomy term.
---
Don't use Microsoft software