How can I search for assets containing a custom field? The field on the asset is called lang. When I use this code no assets are found.
{% set folderId = craft.app.request.getQueryParam('folderId') %}
{% set query = craft.app.request.getQueryParam('q') %}
{% set lang = craft.app.request.getQueryParam('lang') %}
{# Search for assets in the downlaoads folder #}
{% set assets = craft.assets().volume('downloads') %}
{% set assets = assets.folderId(folderId).includeSubFolders() %}
{% set searchQuery = [] %}
{# Check if a query was supplied, if so then search for it. #}
{% if query is not empty %}
{% set searchQuery = searchQuery|merge({query: query}) %}
{% endif %}
{% if lang is not empty %}
{% set searchQuery = searchQuery|merge({query: 'lang:' ~ lang}) %}
{% endif %}
{% paginate assets.search(searchQuery).limit(10) as pageInfo, pageEntries %}
I also tried:
{% set query = query ~ ' lang: ' ~lang %}
{% paginate assets.search(query).limit(10) as pageInfo, pageEntries %}
If I remove the lang part results will show up.
The field is a Dropdown field with languages. Value is ISO code and Label the language name. The variable lang in the code contains nl, en etc.