Alter Exposed filter form I would like to know how to get parent terms only, for example "Ages 0-2" and also print in dropdown. 

This is the structure of the form array.

Array(
  [#info] =&gt; Array(
    [filter-tid] =&gt; Array(
      [operator] =&gt; tid_op
      [value] =&gt; tid
      [label] =&gt; Term
      [description] =&gt; 
    )
  )
  [tid] =&gt; Array(
    [#type] =&gt; select
    [#options] =&gt; Array(
      [All] =&gt; - Any -
      [0] =&gt; stdClass Object(
        [option] =&gt; Array(
          [367] =&gt; Ages 0-2
        )
      )
      [1] =&gt; stdClass Object(
        [option] =&gt; Array(
          [2378] =&gt; -Infant
        )
      )
    )
  )
)


This is the code I am using.

  if ($form['#id']== "views-exposed-form-quick-find") { 
    $test = $form['tid']['#options'];
    foreach ($test as $tid) {
      // It prints "Array" and the "Trying to get property of non-object" message.
      print $tid-&gt;option;
    }
  }


I do not understand why the "Array" text repeats; it could be I am not pointing to right array.

How do I remove all children which do not have "age 12 - 14" (see "-" in the middle not from start)?
What you obtain from that code is exactly what you should obtain.

The values you are getting from that control statement are:


$form['tid']['#options']['All'] is a string, and not an object. Trying to access $form['tid']['#options']['All']-&gt;option gives you a warning about accessing a property for something that is not an object.
$form['tid']['#options'][0] is an object, and it doesn't raise an error, but $form['tid']['#options'][0]-&gt;option is an array, and print $form['tid']['#options'][0]-&gt;option converts it in a string. That is why you see Array.
The same is true for $form['tid']['#options'][1].


To remove the array element that contains 'Age 12 - 14' from $form['tid']['#options'], I would use the following code.

foreach ($form['tid']['#options'] as $index =&gt; $tid) {
  if (is_object($tid) &amp;&amp; !empty($tid-&gt;option) &amp;&amp; is_array($tid-&gt;option) &amp;&amp; in_array('Ages 12-14', $tid-&gt;option)) {
    unset($form['tid']['#options'][$index]);
  }
}


Notice that in_array() is case-sensitive. If you are searching for 'Age 12 - 14', but the string is 'age 12 - 14', the code doesn't remove the option.