> For the complete documentation index, see [llms.txt](https://docs.cwicly.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cwicly.com/blocks/filter/create-a-filter.md).

# Create a Filter

{% embed url="<https://youtu.be/REZx7Ffgv9s?feature=shared&t=233>" %}

The `filter` block is able to filter anything inside a `query` block.

The `filter` block is usually inserted into a parent block.

## Toggle on Frontend Rendering

* Select the Query in the navigator.
* In the Primary tab of the block Inspector open the Settings tab.
* Toggle on Frontend Rendering.

{% hint style="warning" %}
The `filter` block will only work with a `query`block that has the front end rendering property toggled on.
{% endhint %}

<figure><img src="/files/8ej7fNJ4uCGH49RpYSog" alt=""><figcaption></figcaption></figure>

## Categories

For this example, we have already set up our Categories in the WordPress Dashboard.&#x20;

* Navigate to the Dashboard.
* Open the Categories tab and add new categories as required.
* In this example we have set up 3 categories.

<figure><img src="/files/x23stMBE2TLsmMasStEX" alt=""><figcaption></figcaption></figure>

## Set up Filter

* Select Query in the Navigator.
* In the Primary Tab of the Block Inspector, open the Query Editor.
* Open "Taxonomy Query".

<figure><img src="/files/Qe12D2MWkwrScSpPEPUv" alt=""><figcaption></figcaption></figure>

### Open

* Click the "+" icon to add a new Taxonomy Query.
* Click to open.

<figure><img src="/files/tGZYrv6Rt7BqaJyd1Yvz" alt=""><figcaption></figcaption></figure>

### Rename

You can give you taxonomy filter a suitable name.

* Find the Name field.
* Input a suitable name.

<figure><img src="/files/cF9DXzcGyxacw9vyAplm" alt=""><figcaption></figcaption></figure>

### Set Taxonomy Filter

In order to target Categories, you need to filter a Taxonomy, such as Categories, Tags, Navigation Menus, Link Categories, Formats, Themes, Tenplate Part Areas etc.

In this example, we wish to target Categories.

* Set Taxonomy to "Categories - Post".

<figure><img src="/files/PlAcUSzE5VfEVEYNHwMc" alt=""><figcaption></figcaption></figure>

### Dynamic Toggle

In order to filter dynamic data, you need to toggle on the Dynamic icon.

* Find Terms.
* Toggle on the "Dynamic" icon.

<figure><img src="/files/C4s0HNdsBgYnAK8uuZ8r" alt=""><figcaption></figcaption></figure>

### Source

* Set Source to "WordPress".

<figure><img src="/files/XeVxViurxuFcX1ccq01l" alt=""><figcaption></figcaption></figure>

The Filter block adds or removes a parameter that the Query then uses to modify the information that it displays.

* Set Wordpress to "URL Parameter".

<figure><img src="/files/FYhjLdzxpOUjbs2bqPqi" alt=""><figcaption></figcaption></figure>

### Key

You need to input the filter target name, in this example "Category".

* Input "Category" as Key.&#x20;

<figure><img src="/files/ieihXtXsssf2B4NyQ5FT" alt=""><figcaption></figcaption></figure>

### Field

By default, the filter returns taxonomy slugs. If required, you can set it to another parameter such as term\_id, name, term-taxonomy\_id. In this example we wish to return "slugs".

* Select "slug" as Field in the Dropdown.

<figure><img src="/files/l2GdZAxhNvLsU95QTj2p" alt=""><figcaption></figcaption></figure>

## Copy Query ID

You need to copy the query ID so that the Filter can attach to the Query.

* Find Query ID.
* Copy using keyboard shortcuts.

<figure><img src="/files/WNKPXbTwRxmyrNndCRUR" alt=""><figcaption></figcaption></figure>

## Add Filter

Now we need to add our Filter. You can place it where you need it as required.

In this example we will place it above the Query.

* Select the block into which you want to insert the Filter.
* Add a Cwicly Filter block using the Quick Inserter or the Block Inserter.

<figure><img src="/files/55yvwWeRZDPCtXBcdDKa" alt=""><figcaption></figcaption></figure>

* You should see a placeholder with "Select Filter Properties...".

<figure><img src="/files/3pSZ3lkYTmIs0kJhgjGi" alt=""><figcaption></figcaption></figure>

* Click to open the Filter Editor from the Primary tab.

<figure><img src="/files/KT9e1cEJceYCma750dPw" alt=""><figcaption></figcaption></figure>

## Connect Filter to Query

First we need to connect the Filter to the Query using the Query ID.&#x20;

### Query ID

* In the Query Editor modal, input the ID of the Query to which you wish to attach the filter.

![](/files/UdUjdwc6kqODNUKEUNTc)

You can find the Query ID in the Query Editor.

* Select the Query to which you want to attach the Filter.
* In the Primary tab, open the Query Editor.
* Copy the Query ID.

<figure><img src="/files/EVSMHZGiqrKpkCn9ZrBB" alt=""><figcaption></figcaption></figure>

* Input the required Target, in this example "category".

<figure><img src="/files/tJktlKHVSHlkmmzXZHLn" alt=""><figcaption></figcaption></figure>

### Target

The Target is in fact the key that you chose when you set up the Query. You will find it in the Taxonomy Query tab of the Query Editor.

* Select the Query.
* Open the Query Editor.
* Open the Taxonomy Query tab.
* Click the required Query, in this example the "Travel Query".

<figure><img src="/files/lW4YfYJgYuS7PmhTT5JD" alt=""><figcaption></figcaption></figure>

### Key

Copy the Key, in this example "category" and input it into the Target field of the Filter Editor.

<figure><img src="/files/ALLe7VhwUchcllf46xeb" alt=""><figcaption></figcaption></figure>

### Filter Type

Select the Filter Type you require in the dropdown, in this example "Button Single".

Button Single allows you to choose only one Button at a time as opposed to "Button Multiple".

<figure><img src="/files/yOEuKjDplTbz2X905zVQ" alt=""><figcaption></figcaption></figure>

### Data Source

* Select required Data Source in the dropdown in the Filter Editor.
* In this example, Dynamic as we want our data to be dynamic.

![](/files/tb4vi7I3yehcHVfxuvjN)

### Data Type

* Select required Data Type, in this example Taxonomy.

![](/files/BHSFEpj1TxCfWMNo8bqe)

### Taxonomy

Choose required taxonomy type in the dropdown,  In this example want to target Categories as our Taxonomy type.

* In the Taxonomy dropdown select required taxonomy type, in this example Categories.

![](/files/AU9dgWK1P4cXJibSd3V2)

In this example we want to exclude Uncategorised posts and only include those we previously set up in the Dashboard.

* In the Taxonomy section of the Filter modal, select items to exclude in the Exclude dropdown.
* In this example, "Uncategorised".

![](/files/fqENxyKVYaHgZytKitqg)

In this example we do not want to display terms that do not contain any posts.

* In the Taxonomy section of the Filter modal, toggle on "Hide Empty" as required.

![](/files/Lj2twoL96GHMTexbMLUs)

## Filter categories

Now we want to be able to visualise and style the filter categories we have created.

* With the Filter block selected, add a Paragraph.

<figure><img src="/files/ZfsRY8OINxi7pq1X3zRi" alt=""><figcaption></figcaption></figure>

### Connect dynamic data

We need to connect our dynamic data.

* Select the Paragraph and open Dynamic Values from the toolbar.
* Select Filter as Source.

<figure><img src="/files/dAZgei0cD0y4teafFday" alt=""><figcaption></figcaption></figure>

We want the Category names to appear.

* Set Filter to Name.

<figure><img src="/files/0nqgeEAc8OSiAUARXaaI" alt=""><figcaption></figcaption></figure>

Now you can visualise the three Categories we set up.

<figure><img src="/files/JSN3KcCGYDzAkE3LoZtM" alt=""><figcaption></figcaption></figure>

## Layout

Let's turn our attention to the Layout of our Filter.

* In the Primary tab, open the Layout tab.
* Set Flex display, Row direction, Wrap (so that if there are multiple categories, they will display on the next line) and Align centre.

![](/files/ywjQ04HBsS4h5Lob3Fzs)

To add spacing around the filter items:

* Set a Row Gap and a Column gap or !8px.

<figure><img src="/files/46O7sTshu0XWzhdj3Bws" alt=""><figcaption></figcaption></figure>

To Space the Filter items from the Query:

* In the Margin and Padding tab, set a bottom Margin of 50px.

<figure><img src="/files/CMJxPjhJF4Liv3p9wqWU" alt=""><figcaption></figcaption></figure>

## Style

Now we need to Style the Filter Titles.

* In the Typography tab of the Primary tab, set an appropriate font size and weight.

<figure><img src="/files/j88A634dApkfjrPoW8u4" alt=""><figcaption></figcaption></figure>

* In the Design tab, open the Borders tab and the Radius and Border tab.
* Set a 40px equal Radius or as required to give a suitable oval look.
* Set an appropriate Border colour, in this example dark grey.
* Set a solid border Style with an equal 1px Width.

<figure><img src="/files/EAcDLnBYRjle2CRzsvFE" alt=""><figcaption></figcaption></figure>

Set an appropriate Padding to allow the items to breathe.

* In the Design tab, open the Margin and Padding tab and set an upper and lower 10px Padding and a 30px right and left Padding or as required.

<figure><img src="/files/zONsSXrDNAXUyJKNbQRW" alt=""><figcaption></figcaption></figure>

## Relative Styling for button selection

Now we have fully set up the Filter buttons but to make it easier for the User, we can add a colour  change to the current button to let them know what category is selected.

* With the Filter block selected, open the Design tab and the Relative Styling tab.
* Click the "+" icon to add a new Relative Style.

<figure><img src="/files/ONaDVPKckjT6fogOUWSh" alt=""><figcaption></figcaption></figure>

We need to set the Rules under which this change will occur.

* Click the "Rules" icon to open the Relative Styles Rules modal.
* Input a suitable Name, in this example "Selected".

<figure><img src="/files/04ajRNara4IR20kwEknh" alt=""><figcaption></figcaption></figure>

* In  "Rules after block class" set Combinator to "Descendent".

<figure><img src="/files/aWK6pUl97fNAfkgkky5I" alt=""><figcaption></figcaption></figure>

* Set Type to Class.

<figure><img src="/files/CFd4M8lNhrEIWVv1bA5M" alt=""><figcaption></figcaption></figure>

* Input "selected" as Selector since we wish the rule to apply to the selected filter item.
* Click Create "selected" to create.

<figure><img src="/files/WBWUrR7gSWgiHtuHkJpG" alt=""><figcaption></figcaption></figure>

We want to add another Rule to target the selected paragraph.

* Click the "+" icon in  Rules after block class.

<figure><img src="/files/r6RrfEpz7H9NfKL28RRh" alt=""><figcaption></figcaption></figure>

* Set Combinator to Descendant.

<figure><img src="/files/s1EI0WPR3758Os4PCW3p" alt=""><figcaption></figcaption></figure>

* Set Type to Class.

<figure><img src="/files/BorvjplT8q0fxVSpnCkP" alt=""><figcaption></figcaption></figure>

* In the Navigator, right click on the Paragraph block contained inside the Filter block and copy the Class.

<figure><img src="/files/irwHTfH54M2gw8FJRyyN" alt=""><figcaption></figcaption></figure>

* Paste the copied paragraph class into the Selector field.

<figure><img src="/files/JrirHquBpBI5AYKEGD6u" alt=""><figcaption></figcaption></figure>

It's time to style the relative styling we set up.

* In the Design tab, open the Relative styling tab.
* Click the required Relative Style you wish to customise, in this example "Selected".

![](/files/0xXhXAd8vYOx3Io6k7D8)

In this example we want the white background to become black when selected.

* In the Background tab, open the colours tab and choose a suitable background colour, in this example Black.

![](/files/3qXVltQsqFfuS3ZBcsnP)

Let's style the text. In this example we want the text to change white when selected.

* In the Typography tab, select a suitable Text colour, in this example white.

![](/files/04STAotUwzglBAPue8uW)

Now when a user selects a filter button, the background will turn black and the text white.

<figure><img src="/files/vzFmMEgqJaTKwWQ7dZN3" alt=""><figcaption></figcaption></figure>
