How to get all users with active Commerce 2 subscription How do I get all the users with an active subscription in Commerce 2? I want to be able to filter entries by subscribed users.
I solved this by creating a simple plugin.

use craft\db\Query;

class MyPluginVariable
{
      public function allActivelySubscribedUserIds()
      {
           $subscribedUserIds = (new Query())
                -&gt;select('userId')
                -&gt;from(['{{%commerce_subscriptions}}'])
                -&gt;distinct()
                -&gt;all();

            // Create array of just user IDs
            $subscribedUserIds = array_column($subscribedUserIds, 'userId');

            return $subscribedUserIds;
       }
 }


I my case I needed to display all entries authored by users that are currently subscribed. In my template I used the variable like this:

{% set subscribedUserIds = craft.MyPlugin.allActivelySubscribedUserIds %}

{% set entries = craft.entries()
    .authorId(subscribedUserIds)
    .all()
%}