Showing posts with label get the parent id. Show all posts
Showing posts with label get the parent id. Show all posts

Tuesday 19 March 2019

How to get the Parent id from term id in drupal 8?

It's easy way to tackle this problem, Sometimes we face this issue and take the query help and get the parent id, but we have here solution for this issue.

Just write the loadParent syntax as per given instructions:

Syntax:

$term_id = $node->get('field_category')->target_id;
$term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->load($term_id);
$parentids = $term->parent->target_id;

OR

 $parent = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadParents($term_id);   // here term_id is child term id
 $parent = reset($parent); //reset the parent array
 $parentids = $parent->id();    //get the parent id  


Note: If have any suggestions or issue regarding 'How to get the Parent id from term id in drupal 8?' then you can ask by comments.

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error: Steps:   You can put t...