My search form has a drop down of tags from different tag groups.
My current search code for the input query is
{% set sentries = craft.entries({
search: query,
section: ['projects','projectStories'],
order: 'score'
}) %}
How do I take the single tag (drop down select value) and find entries from these sections in the search?
I have 4 tag groups and the select tag for search can be from any one them. Eg my tag groups look like:
{% set searchLocationNuts = craft.tags().group('locationNuts') %}
{% set searchFundingP = craft.tags().group('fundingProgramme') %}
{% set searchLA = craft.tags().group('localAuthority') %}
Im not sure if relatedTo is meant to be used with targetElement or if there is a needto grab all tag ids and merge them for search. And i am not sure if the tag search should be tag name or tag slug.
Pointers welcome:)
** Solution **
{% set tagfilter = craft.app.request.getParam('tagfilter') %}
{% set tag = craft.tags.slug(tagfilter).one() %}
{% set query = craft.app.request.getParam('q') %}
{% set sentries = craft.entries({
search: query,
section: ['projects','projectStories'],
relatedTo: tag,
order: 'score'
}) %}