I used this

    $this->termStorage->loadByProperties(['name' => 'test']);

I got two terms: Test, test. I want to get only one: test

This is working without case-sensitive:

    $this->termStorage->getQuery()->condition('name', 'test', '=')->execute();
    \Drupal::database()->select('taxonomy_term_field_data', 't')
      ->condition('t.name', 'test')
      ->fields('t', ['name'])
    \Drupal::database()->query("SELECT name FROM taxonomy_term_field_data WHERE name='test'")->fetchAll();
  • 1
    See this D7 topic, besides EntityFieldQuery being replace by EntityQuery this should still be valid for D8: drupal.stackexchange.com/questions/77780/… – 4k4 Oct 30 '19 at 13:00
  • 1
    Alternatively just use PHP to compare the string with the loaded terms' names. – Beebee Oct 30 '19 at 13:18

To retrieve result with sensitive case, you can use binary in where clause:
Like this sql query.

SELECT name FROM taxonomy_term_field_data WHERE binary name='test'

For Drupal you can use \Drupal::database()->select with where conditions take a look here .

Try this:

 $result = \Drupal::database()->select('taxonomy_term_field_data', 't')
      'binary name = :term_name',
      ['term_name' => 'test']
    ->fields('t', ['name'])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.