Get entries based on multiple fields in controller I am trying to get the entries based on multiple fields.
Fields can be of type tags, checkbox, radio box, and number.

In my controller currently what I tried is.

$extrafilter will be like

Array
(
    [0] =&gt; Array // other field
        (
            [handle] =&gt; amenities
            [value] =&gt; laundry
        )

    [1] =&gt; Array // tag field
        (
            [handle] =&gt; technologies
            [value] =&gt; 45
        )

)


Code to narrow down the result.

use Craft;
use craft\elements\Entry;
use craft\elements\db\ElementQuery;

$entryQuery = Entry::find();
$entryQuery-&gt;section($sectionName);

if ($extrafilter &amp;&amp; !empty($extrafilter[0])) {
  $relatedTo = [];
  $fieldList = [];

  foreach ($extrafilter as $key =&gt; $value) {
     $relatedTo[] = $value['value'];
     $fieldList[] = $value['handle'];
  }

  $entryQuery-&gt;relatedTo = array(
        'targetElement' =&gt; array_merge(['and'], $relatedTo),
        'field' =&gt; $fieldList,
  );
}
$entries = $entryQuery-&gt;all();


This works for Tags but for other fields it dont give any result.

I checked these Questions 


Display entries that meet multiple tag params
I haven't tested it but it should give you a pretty good idea on how to set this up.

public function actionTest() {
    $entryQuery = Entry::find()-&gt;section('mySection');

    // All the element relations. For example tags and categories.
    // These have to be Element objects. For example craft\elements\Tag.
    $myArrayWithTags = [/* ... */];
    $myArrayWithCategories = [/* ... */];
    $allRelations = array_merge($myArrayWithTags, $myArrayWithCategories);

    // Filter by relations
    $this-&gt;_applyRelationFilter($entryQuery, $allRelations);

    // Filter by custom fields
    $this-&gt;_applyFieldFilter($entryQuery, 'myRadioField', 'value2');
    $this-&gt;_applyFieldFilter($entryQuery, 'myNumberField', 3);
    $this-&gt;_applyFieldFilter($entryQuery, 'myCheckboxField', ['option1', 'option2']);

    // Build response string
    $content = "Entries:&lt;br&gt;";
    $content .= "&lt;pre&gt;" . json_encode($entryQuery-&gt;all()) . "&lt;/pre&gt;";

    // Respond
    $response = Craft::$app-&gt;getResponse();
    $response-&gt;content = $content;
    return $response;
}

private function _applyRelationFilter(ElementQuery $query, array $elements) : array {
    $relatedTo = [];

    // Build the list of relations in the correct format
    foreach($elements as $element) {
        array_push($relatedTo, [
            "targetElement" =&gt; $element
        ]);
    }

    // Create an array with and as the first value so 
    // the result only contains elements that have all the set relations
    $relatedTo = array_merge(['and'], $relatedTo);

    // Set query relatedTo
    return $query-&gt;relatedTo($relatedTo);
}

private function _applyFieldFilter(ElementQuery $query, string $handle, $value) {
    $query-&gt;andWhere([
        ('content.field_' . $handle) =&gt; $value
    ]);
}


You need to have the following imports:

use Craft;
use craft\elements\Entry;
use craft\elements\db\ElementQuery;


Info about querying by custom field:
https://craftcms.stackexchange.com/a/22995/9754