What is wrong with this code? I am having a slight problem with my code; I am trying to do a if statement to make the date not print if a node is using a certain term. I have parsed $node to narrow down what term I would like to exclude the date from being used.

This is what is returned in the dump: 


Array ([und] => Array ([0] => Array ([tid] => 103 )))


This is what I have for my code to have the date being displayed:

      if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
        $node = node_load(arg(1));
        $user = user_load(array('uid' =&gt; $node-&gt;uid));
        foreach ($node-&gt;field_newsections['und']['0'] as $node_time);
      }

      hide($content['comments']);
      hide($content['links']);
      $nodecontent = render($content);
      $newcontent = preg_replace("/&lt;p[^&gt;]*?&gt;/", "", $nodecontent);
      $newcontent = str_replace("&lt;/p&gt;", "&lt;br /&gt;&lt;br /&gt;", $newcontent);

      if ($node-&gt;type == 'post' || 'news') {
        echo '&lt;div id="date-created"&gt;'. date('l, F j, Y g:ia', $node-&gt;created). '&lt;/div&gt;';
      }
      else ($node_time == '108') {
        echo 'working';
      }

      print render($newcontent);


I am probably over looking something small.
There are three things that needs to be corrected, in your code.


You are using a foreach statement without any block; this means that that control statement is not doing anything.

foreach ($node-&gt;field_newsections['und']['0'] as $node_time);

You are using an else statement followed by a condition; or you use an else statement without condition, or you really meant to use the elseif statement.

else ($node_time == '108') {
  //...
}

You are using render() with $newcontent, which is set with a previous call to render().

$nodecontent = render($content);
$newcontent = preg_replace("/&lt;p[^&gt;]*?&gt;/", "", $nodecontent);
$newcontent = str_replace("&lt;/p&gt;", "&lt;br /&gt;&lt;br /&gt;", $newcontent);


While render(), which returns a string, checks when the parameter it gets is a string, instead of an array, and it returns that parameter immediately, it is useless to call render() with the result of a previous call to render(), even if that string has been modified from any function to alter a string.


Also, as you said (in a comment for this answer) that you are using that code inside the "node.tpl.php" template file, that template file has already access to the $nodevariable that contains the node object for the node being shown. As the template file is only used for nodes, the following code is useless:

if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
  $node = node_load(arg(1));
  $user = user_load(array('uid' =&gt; $node-&gt;uid));
  // …
}


It is also unusual for a theme replacing the HTML content; that is normally done in a module.

Supposing that you are trying to use the last item in the $node-&gt;field_newsections['und']['0'] array (which seems a term array), I would rather use the following code:

$tid = array_pop($node-&gt;field_newsections['und']);
$node_time = $tid['tid'];

hide($content['comments']);
hide($content['links']);
$nodecontent = render($content);
$newcontent = preg_replace("/&lt;p[^&gt;]*?&gt;/", "", $nodecontent);
$newcontent = str_replace("&lt;/p&gt;", "&lt;br /&gt;&lt;br /&gt;", $newcontent);

if ($node_time != '103') {
  print '&lt;div id="date-created"&gt;'. date('l, F j, Y g:ia', $node-&gt;created). '&lt;/div&gt;';
}

print $newcontent;