How to programmatically search content with a specific taxonomy term with Search API? I'm working on programmatically searching content with the Search API module. Ideally I would like the ability to select which taxonomy term of a content type is being searched. For example, if I have a content type of 'restaurants' and three taxonomy terms representing the style of restaurants, lets say 'Italian', 'Chinese' and 'Fast Food'. I would then like the ability to search and get results of all the restaurants content entities associated with, lets say, just the Chinese taxonomy term.

Here is the code that I have so far: 

$search_entry = $form_state-&gt;getValue('search');

$query = \Drupal\search_api\Entity\Index::load('forum_ct_search')-&gt;query();
$query-&gt;keys($search_entry);
$query-&gt;range(0, 5);

$result = $query-&gt;execute();
$items = $result-&gt;getResultItems();


This is working as far as I'm able to search the specific content type I'm interested. However I'm assuming there is a way to ask the Search API to just search by taxonomy terms. If it's possible, my best guess is that it is with the addCondition method, such as this: 

$query-&gt;addCondition('type', ['article', 'snippet'], 'IN');


If this is the correct method for filtering by taxonomy term what are the correct parameters? If not how may I?

The other alternative would be to weed out the taxonomy terms from the results. This would work but it strikes me as cleaner to do it the other way.

Any ideas? Thanks!

(I'm running Drupal 8.6 with Search API 1.12)
Yes that's right to do addCondition here's a page with some examples https://www.drupal.org/docs/8/modules/search-api/developer-documentation/executing-a-search-in-code

So you'd just need to do the machine name of your indexed taxonomy field 

$query-&gt;addCondition('my_indexed_field', $myvalue)