Fetch Entries with Tags Only I'm trying to get all the entries which have tags associated with them. 

At the moment I'm doing: 

$entries = Entry::find()-&gt;with('tags')-&gt;all();


and then filtering the results in PHP as follows: 

$filteredEntries = array_filter($entries, function($entry) {
    return count($entry['tags']) &gt; 0;
});


This works fine, but I am still fetching all the entries, even without tags from the DB - I think this can be more efficient if I can specify in my query that I only want the entries with tags associated to them. How can I do this?
What you are looking for is the relatedTo parameter (docs) and this post will also help.

If you wanted to return any entries which has (any) tags attached, you could do:

$entries = Entry::find()-&gt;tags(':notempty:')-&gt;all();


Where tags is the handle of your tags field.