Skip to main content
added 94 characters in body
Source Link
Deejay
  • 670
  • 3
  • 17

Due to 'Hierarchical Term Formatter ' causing issue with existing information here'sThe following code takes the solution I usedabsolute child tid and grabs all parents.

to make a template override.

explode $output into array .

I know that I will only have 4 maximum values here The second argument is for the amount of terms you wish to return; and the thrid for how you want to order it.

use a foreach statment that iterates through these values and makes another array with Parent name and tid data attached

$result =/**
 db_query('SELECT* ttd.name,@file tth.parent,Orders ttd.tidTaxonomy
 *
 FROM* {taxonomy_term_data}@param ttd$output LEFT- JOINexpecting {taxonomy_term_hierarchy}a tthtid ON ttd.tid// =check tth.tidthis at WHEREthe ttd.namepoint =of :locationrunning ',the array(':location' => $location_trimmed));


 function
 * @param $no_results if- ($resultthe !=number NULL)of {results that you'd like to return
 * @param $order - which tid first - child or most foreachsenior parent ?
 */

 function taxonomy_order($result$output, as$no_results $record= 1, $order = 'first') { 

  $terms = entity_load('taxonomy_term', array($output));
  $wrapper = entity_metadata_wrapper('taxonomy_term', $output);
  $locations[$key]['parent']$all_parents = $record$wrapper->parent;>parents_all->value();

  ( $order == 'last' ) ? $all_parents = array_reverse($all_parents) : $all_parents;

  $locations[$key]['location_name']$stitch_term_array = $record->name;'';
  foreach ($all_parents as $key => $term) {
   ($key < $no_results ) ? $locations[$key]['location_tid']$stitch_term_array .= $record$term->tid;
>name . ", " : '';
   }
  $stitch_term_array = }rtrim($stitch_term_array, ', ');

  return $stitch_term_array;

Then I've written some conditional statements to put them in order , using

array_push,array_unshift & array_splice .

Due to 'Hierarchical Term Formatter ' causing issue with existing information here's the solution I used.

to make a template override.

explode $output into array .

I know that I will only have 4 maximum values here.

use a foreach statment that iterates through these values and makes another array with Parent name and tid data attached

$result = db_query('SELECT ttd.name, tth.parent, ttd.tid  FROM {taxonomy_term_data} ttd LEFT JOIN {taxonomy_term_hierarchy} tth ON ttd.tid = tth.tid  WHERE ttd.name = :location ', array(':location' => $location_trimmed));



    if ($result != NULL) {
        foreach ($result as $record) {
            $locations[$key]['parent'] = $record->parent;
            $locations[$key]['location_name'] = $record->name;
            $locations[$key]['location_tid'] = $record->tid;
        }
    }

Then I've written some conditional statements to put them in order , using

array_push,array_unshift & array_splice .

The following code takes the absolute child tid and grabs all parents. The second argument is for the amount of terms you wish to return; and the thrid for how you want to order it.

 /**
 * @file Orders Taxonomy
 *
 * @param $output - expecting a tid  // check this at the point of running the    function
 * @param $no_results - the number of results that you'd like to return
 * @param $order - which tid first - child or most senior parent ?
 */

 function taxonomy_order($output, $no_results = 1, $order = 'first') { 

  $terms = entity_load('taxonomy_term', array($output));
  $wrapper = entity_metadata_wrapper('taxonomy_term', $output);
  $all_parents = $wrapper->parents_all->value();

  ( $order == 'last' ) ? $all_parents = array_reverse($all_parents) : $all_parents;

  $stitch_term_array = '';
  foreach ($all_parents as $key => $term) {
   ($key < $no_results ) ? $stitch_term_array .= $term->name . ", " : '';
   }
  $stitch_term_array = rtrim($stitch_term_array, ', ');

  return $stitch_term_array;
Source Link
Deejay
  • 670
  • 3
  • 17

Due to 'Hierarchical Term Formatter ' causing issue with existing information here's the solution I used.

to make a template override.

explode $output into array .

I know that I will only have 4 maximum values here.

use a foreach statment that iterates through these values and makes another array with Parent name and tid data attached

$result = db_query('SELECT ttd.name, tth.parent, ttd.tid  FROM {taxonomy_term_data} ttd LEFT JOIN {taxonomy_term_hierarchy} tth ON ttd.tid = tth.tid  WHERE ttd.name = :location ', array(':location' => $location_trimmed));



    if ($result != NULL) {
        foreach ($result as $record) {
            $locations[$key]['parent'] = $record->parent;
            $locations[$key]['location_name'] = $record->name;
            $locations[$key]['location_tid'] = $record->tid;
        }
    }

Then I've written some conditional statements to put them in order , using

array_push,array_unshift & array_splice .