Get entries based on custom field lightswitch in custom plugin in Craft 2 I am trying to get the entries in my custom plugin template ( CP )

Each entry has a lightswitch I want to fetch only those where lightswitch is enabled.

In controller file:

$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section('articles');
$criteria-&gt;relatedTo(array(
    'field' =&gt; 'lightswitchFieldHandle'
));
$criteria-&gt;limit = 20;
$products['entries'] = $criteria-&gt;find();
$this-&gt;renderTemplate('sponsoredentries/_index', $products);


But I am getting 20 entries (as per limit but not as per field)
You need to set the value of your Lightswitch field directly instead of using the relatedTo parameter

$criteria-&gt;lightswitchFieldHandle = '1';