good to be back)
Helping a friend out with a website for his tiling business. The site contains a 'projects' section which displays category-filter buttons allowing the user to toggle relevant projects.
The CMS also contains a custom field to allow my friend to make a project entry 'sticky'.
I had been struggling to make this work:
{# get all sticky Project entries #}
{% set stickyProjects = craft.entries().section('project').limit(30).sticky('1') %}
{% set stickyProjectEntries = stickyProjects.all() %}
{# get all non sticky Project entries #}
{% set projects = craft.entries().section('project').limit(30).sticky('0') %}
{% set projectEntries = projects.all() %}
{# Fetch, then merge, categories related to both sticky and non-sticky Projects #}
{% set stickyCategories = craft.categories.relatedTo({ sourceElement: stickyProjectEntries }).all() %}
{% set nonStickyCategories = craft.categories.relatedTo({ sourceElement: projectEntries }).all() %}
{% set usedCategories = stickyCategories|merge(nonStickyCategories) %}
Even after using the Merge filter, "usedCategories" was outputting a duplicate category "External" (see image)