How to get content with their taxonomy term name and id? Hello I have created content type product. I also add Taxonomy with name "category". I add field in with term reference in product content type.
Now I want to get all content with taxonomy name and id which have  content type named "product" using query in Drupal 8 .
Make a dynamic query like this:

$query = \Drupal::database()-&gt;select('node_field_data', 'nfd');
$query-&gt;condition('nfd.type', 'product');
$query-&gt;leftJoin('node__field_category', 'ft', 'ft.entity_id = nfd.nid');
$query-&gt;leftJoin('taxonomy_term_field_data', 'fd', 'fd.tid = ft.field_category_target_id');
$query-&gt;fields('fd', ['tid', 'name']);
$query-&gt;fields('nfd', ['nid']);
$results = $query-&gt;execute()-&gt;fetchAll();


Suppose the reference field taxonomy machine name is "node__field_category".
The result of the query will be node id , term name and term id.