---
title: "How to filter entries by cookie value"
date: 2026-04-23
author: "GravityKit"
link: "https://www.gravitykit.com/docs/gravityview/advanced/how-to-filter-entries-by-cookie-value/"
---

In this article, we'll show you how to filter entries using the value of a [cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies). This example will show you how to hide a specific entry, but this is just a basic use case.

The better use case is to filter multiple Views using the same cookie, removing the need to filter by URL parameters.

### Useful for report dashboards and applications:

- Set a "Customer ID" cookie and embed multiple Views with all the Gravity Forms orders they have placed as well as the contact forms they have submitted.
- Set a "Client ID" and see a dashboard of surveys, tasks, contact submissions.
- Set a "Student ID" and see all their submitted quizes, questions, and more, across multiple forms.

You can use this method of filtering using cookies instead of filtering using [the `{get}` Merge Tag](https://www.gravitykit.com/docs/gravityview/merge-tags/the-get-merge-tag/) and needing to pass around URL parameters.

## Add a `{cookie}` Merge Tag to Gravity Forms

We created code that adds a Gravity Forms Merge Tag named `{cookie}` . This Merge Tag will be used to filter entries in a View.

[**First, add this code to your website.**](https://gist.github.com/zackkatz/3e0667288869977096e55708066d103d)

Not sure where to add this code? Follow the steps in the [Where to put code samples](https://www.gravitykit.com/docs/gravityview/customizing-your-views/where-to-put-code-samples/) doc.

Great, now we need to set the cookie!

## Update the Custom JavaScript View setting

In the View Settings section, click the Custom Code tab, and add the following script:

```
document.addEventListener('DOMContentLoaded', function() {
    // Set the cookie
    document.querySelectorAll('.gvCookieSetter').forEach(function(link) {
        link.addEventListener('click', function() {
            document.cookie = "current_entry_id=" + this.getAttribute('data-entry-id') + "; path=/";
        });
    });

    // Clear the cookie
    var clearCookieLink = document.querySelector('.gvClearCookie');
    if (clearCookieLink) {
        clearCookieLink.addEventListener('click', function() {
            document.cookie = "current_entry_id=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
        });
    }
});
```

```
document.addEventListener('DOMContentLoaded', function() {
    // Set the cookie
    document.querySelectorAll('.gvCookieSetter').forEach(function(link) {
        link.addEventListener('click', function() {
            document.cookie = "current_entry_id=" + this.getAttribute('data-entry-id') + "; path=/";
        });
    });

    // Clear the cookie
    var clearCookieLink = document.querySelector('.gvClearCookie');
    if (clearCookieLink) {
        clearCookieLink.addEventListener('click', function() {
            document.cookie = "current_entry_id=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
        });
    }
});
```

![Settings panel for adding custom CSS and JavaScript to set or clear cookies in GravityView](https://www.gravitykit.com/wp-content/uploads/2025/10/file-mJGhBQLpek-scaled.png)

## Add links to set the cookie

Create a Custom Content field and add the following HTML:

```
Hide This Entry
```

```
a href="#" class="gvCookieSetter" data-entry-id="{entry_id}">Hide This Entrya>
```

The entry ID will be replaced with the ID of the current entry being displayed.

![Custom content settings with HTML example to hide entry by cookie value](https://www.gravitykit.com/wp-content/uploads/2025/10/file-j109RpoCxc.png)

## Add a widget to clear the cookie

Click "Add Widget" in the Top Widgets zone, then click Custom Content.

![Widgets menu with options for Calendar, Custom Content, Search Bar, Gravity Forms, Page Size, Show Pagination](https://www.gravitykit.com/wp-content/uploads/2025/10/file-pNw2GQzkuU.png)

## Add a Clear Cookie link to the Custom Content widget

Click the gear icon to configure the Custom Content widget. Add the following code to the Custom Content textarea:

```
Show Hidden Entries
```

```
a href="#" class="gvClearCookie">Show Hidden Entriesa>
```

## Add a filter to the View

Now, when clicking the link, a cookie will be set with the current entry ID. You now want to filter the values shown in the View to only show values that are associated with that entry ID.

The filter setup will likely be different for your use case! This is just an example.

![Advanced filter setup showing exclusion of current entry ID using a cookie value](https://www.gravitykit.com/wp-content/uploads/2025/10/file-cE7hqebdmG.png)

## Save the View and see your work

Visit the View and you should see a "Hide This Entry" link next to each of your entries.

Click one of the "Hide This Entry" links and refresh the page. You should see that the entry you just clicked is hidden!

Click the "Show Hidden Entries" link, and that entry should be visible again.