I am creating a form that searches the FAQ with the search term typed and the taxonommy term selected, i.e., the form will contain a search field and a select list of taxonomy terms associated with the FAQ. So I needed a sql query to achieve this. I need some modifications on this

db_query("SELECT question, nid
  FROM {faq_questions}
  WHERE question LIKE :term
  ORDER BY question asc", array(':term' => '%%' . $term . '%%')); 
so that taxonomy term associated with question is also searched. The above code just searches FAQ with keyword only, not combined with taxonomy term selected


Finally I managed to get results by using this code

db_query("SELECT faq_questions.question, faq_questions.nid,taxonomy_index.tid
FROM faq_questions JOIN taxonomy_index ON faq_questions.nid = taxonomy_index.nid JOIN taxonomy_term_data ON taxonomy_index.tid =taxonomy_term_data.tid WHERE question LIKE '%$keys%' AND taxonomy_term_data.tid='$tid'");

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.