Search code examples
drupal-7drupal-webform

How to programmatically get all nodes which are related to the specific term ID?


What I want to do?

I want to display all categories in first drop down and in second all titles of related nodes with the selected category.

To get that I have mentioned all the tasks I have done. Please read below.

  1. Created taxonomy named category with terms listed Laptop, Car, Mobile etc.

  2. Content type named product with fields title, description, category etc. The category field uses term reference of category taxonomy.

  3. Created a form with WebForm with fields named category and productas drop down
  4. First, categories drop down field, displayed all categories (Laptop, Car, Mobile) by using WebForm Term Options.
  5. Second, product drop down field is empty yet.

I have used hook_form_FORM_ID_alter() hook to alter the webForm I created. I have found the solution to get all the nodes pragmatically those are related with specific taxonomy term ID.

My first question is how to display all these nodes' titles in existing drop down field?

Another question is on category change, products must be change according to its nodes like ajax?


Solution

  • I asked the same question on Drupal Stack Exchange. Here is the solution https://drupal.stackexchange.com/questions/225840/how-to-programmatically-get-all-nodes-which-are-related-to-the-specific-term-id/225855?noredirect=1#225855