Taxonomy term based content how do I get taxonomy based node content through custom query? I have taxonomy terms displayed using drupal api function. Now I need to fetch content based on terms id or name from database? Can any one please help me.Either using entity field query or SQL?

$tree=taxonomy_get_children(1);
 foreach ($tree as $term)
 {
 $item[] = $term-&gt;name;
 $child_term = taxonomy_get_children($term-&gt;tid);
 if (!empty($child_term))
 {
 &lt;a href="?name=&lt;?php print $term-&gt;tid; ?&gt;"&gt;
 &lt;?php
 print $term-&gt;name."&lt;br&gt;";
 ?&gt;
 &lt;/a&gt;
 foreach ($child_term as $child)
 {
 $item[] = $child-&gt;name;
 &lt;a href="?tid=&lt;?php print $child-&gt;tid; ?&gt;" name="tid"&gt; 
 &lt;?php
 print $child-&gt;name."&lt;br&gt;";
 ?&gt;
 &lt;/a&gt;
 &lt;?php
 $nodes = taxonomy_select_nodes($child-&gt;tid);
 $node = node_load_multiple($nodes);
 $nidd=(int)$node-&gt;nid;
 foreach($node as $node1):
 $tids = field_get_items('node', $node1, 'field_product_sub_cat');
 foreach ($tids as $tid){
 if($tid['tid'] == $child-&gt;tid){
 print $node1-&gt;title;
 print render(field_view_field('node', $node1, 'body')); 
 }
 }
 endforeach;
 else
 print $term-&gt;name."&lt;br&gt;";
You can get nodes as shown below:

$nodes = taxonomy_select_nodes($tid); // $tid is term id
$nodes = node_load_multiple($nodes);


Ref: taxonomy_select_nodes -> https://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.module/function/taxonomy_select_nodes/7

Update #1

To get some fields out of $node object use following:

foreach($nodes as $node):
    $tids = field_get_items('node', $node, '&lt;TERM_FIELD_NAME&gt;');
    foreach ($tids as $tid){
        if($tid['tid'] == &lt;SELECTED_TID&gt;){
            print $node-&gt;title;
            print render(field_view_field('node', $node, 'body')); 
            print render(field_view_field('node', $node, 'tags')); 
        }
    }
endforeach;


To render complete node you can use node_view function. In order to render multiple nodes you can use node_view_multiple function as shown below:

$content = node_view_multiple($nodes, 'full');
print render($content);