Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save algotrader-dotcom/674bc6b10b646be5633f08e91fce9546 to your computer and use it in GitHub Desktop.

Select an option

Save algotrader-dotcom/674bc6b10b646be5633f08e91fce9546 to your computer and use it in GitHub Desktop.
Drupal 8 - Load term by name programtically
<?php
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once 'autoload.php';
$kernel = new DrupalKernel('prod', $autoloader);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
use Drupal\node\Entity\Node;
use Drupal\file\Entity\File;
use Drupal\taxonomy\Entity\Term;
// Load term by name
$value = 'test 2';
$terms = taxonomy_term_load_multiple_by_name($value,'tags');
$term_ids = [];
foreach($terms as $term){
//print $term->get('tid')->value."\n";
$term_ids[] = $term->get('tid')->value;
}
// Delete term by id
// entity_delete_multiple('taxonomy_term',$term_ids);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment