Answers.Body: <p>I had to use a bunch of conditionals to accomplish this - it's not ideal but here's what I came up with</p>
  
  <pre><code>{% set category = craft.app.request.getParam("category") %}
  {% set function = craft.app.request.getParam("function") %}
  {% set industry = craft.app.request.getParam("industries") %}
  
  {% if not category | length %}
          {% set category = "blog,caseStudies,videos,webinar,whitePapers" %}
  {% endif %}
  
  {% set category = category | split(',') %}
  
  
  {% set posts = craft.entries({
      section: category,
      orderBy: "postDate desc"
  }) %}
  
    {% if function | length %}
      {% set functionSection = craft.categories.group('businessFunction').slug( function|split(',') ) %}
      {% set posts = posts.relatedTo(functionSection) %}
    {% endif %}
  
    {% if industry | length %}
      {% set industrySection = craft.categories.group('industry').slug( industry|split(',') ) %}
      {% set posts = posts.relatedTo(industrySection) %}
    {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-03T15:25:14.620Z
Answers.LastActivityDate: 2018-12-03T19:45:58.873Z
Answers.LastEditDate: 2018-12-03T19:45:58.873Z
Answers.UserDisplayName: Matthew Rotter
Body: <p>I have a filter with a few different parameters that get pulled in and I was wondering if there was a relatedTo wildcard that I could use.</p>
  
  <p>Here's the relevant code: </p>
  
  <pre><code>{% set function = craft.app.request.getParam("function") %}
  
  {% set functionSection = 'craft.categories.group('businessFunction')'  %}
  
  {% if function | length %}
      {% set functionSection = craft.categories.group('businessFunction').slug( function|split(',') ) %}
  {% endif %}
  
  
  {% set posts = craft.entries({
            section: category,
            relatedTo: [
                'and',
                { element: functionSection } 
            ]
  }) %}
  </code></pre>
  
  <p>The problem is if an entry doesn't have any Business Function selected then it's not related. I could have a conditional that ignores the relationship but there's multiple relations in the real code - it'd be easier if I could set functionSelect equal "all" or something similar.</p>
  
Tags: <categories><relations><relatedto>
Title: Relation fallback if no category has been selected
ThreadText: # Relation fallback if no category has been selected
  
  (Asked by: username_0 on 2018-11-29)
  
  I have a filter with a few different parameters that get pulled in and I was wondering if there was a relatedTo wildcard that I could use.
  
  Here's the relevant code:
  
  ```
  {% set function = craft.app.request.getParam("function") %}
  
  {% set functionSection = 'craft.categories.group('businessFunction')'  %}
  
  {% if function | length %}
      {% set functionSection = craft.categories.group('businessFunction').slug( function|split(',') ) %}
  {% endif %}
  
  {% set posts = craft.entries({
            section: category,
            relatedTo: [
                'and',
                { element: functionSection } 
            ]
  }) %}
  
  ```
  
  The problem is if an entry doesn't have any Business Function selected then it's not related. I could have a conditional that ignores the relationship but there's multiple relations in the real code - it'd be easier if I could set functionSelect equal "all" or something similar.
  
  **Tags:** categories, relations, relatedto
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-12-03. Score: 1
  
  I had to use a bunch of conditionals to accomplish this - it's not ideal but here's what I came up with
  
  ```
  {% set category = craft.app.request.getParam("category") %}
  {% set function = craft.app.request.getParam("function") %}
  {% set industry = craft.app.request.getParam("industries") %}
  
  {% if not category | length %}
          {% set category = "blog,caseStudies,videos,webinar,whitePapers" %}
  {% endif %}
  
  {% set category = category | split(',') %}
  
  {% set posts = craft.entries({
      section: category,
      orderBy: "postDate desc"
  }) %}
  
    {% if function | length %}
      {% set functionSection = craft.categories.group('businessFunction').slug( function|split(',') ) %}
      {% set posts = posts.relatedTo(functionSection) %}
    {% endif %}
  
    {% if industry | length %}
      {% set industrySection = craft.categories.group('industry').slug( industry|split(',') ) %}
      {% set posts = posts.relatedTo(industrySection) %}
    {% endif %}
  
  ```
  
  
  ---
  
  