Hyperlink to dynamic page filter

Hello,
I tried to find an answer to my question to the forum but didn’t find it.

Is there a way to link to a dynamic category page with filter already applied ?

I have a database with books, descriptions, etc… and their collections.
I would like to create a menu entry that link to the dynamic category page showing only the books from one collection for example. Or make another link (in my menu) to the same category page showing this time the books with the same weight, etc…

I know how to apply filter to the category page, but I would like this one page to show different elements based on the menu item we click.

I’m pretty sure it’s possible, but I can’t find a way.

Thanks in advance for you help :wink:

1 Like

Everything is possible :slight_smile:
I didn’t understand your question very well. Do you want to make a filter and then redirect to another page ?

  1. For example the user can filter all books from colleaction “a”
  2. There is a button or anything where stands: "Klick here to see all books from collection “a” ?

May you can send a link to your page.

Hello Nick.

Thanks for your reply. Here is what I would like to do.

Menu entry “collection 1” has to link to “books category page” with filter “collection 1 only visible”

Menu entry “collection 2” has to link to “books category page” with filter “collection 2 only visible”

Etc…

I just need to be able to link any text / button to this dynamic category page. But instead of showing the whole database, I would like the dynamic page to show only specific informations based on what the user clicked (in the menu for example).

If the user click the button “thriller”, the dynamic page only show the thriller books.
If the user click the button “romance”, the dynamic page only show the romance books.

Etc…

In the editor can apply a filter to the category page to show specific informations BUT the filter is fixed once saved. It will always show the same informations of the database. I would like the filter to be “dynamic”.

Thanks.

Hey,
you can connect a button with a link. For example Button romance redicects to /romance
The easiest way is to create multiple pages for all collections.

Means a page for romance with a dataset filter
a page for thriller with a dataset filter

Is it that, what you’re looking for ?

Ok.

So there is no way to add a sort of filter value in the link then ?

Like :

mysite .com/books+filter=collection-thriller 

or

mysite .com/books+filter=collection-romance

I know I can create different page with each filter but I’like to avoid it because there are a lot of filters and tags which means a lot of pages… while we could only use one page showing informations on demand…

Any idea to make it efficient ?

Thanks

Then you need a very complex filter code. Can you send me a picture of your database please and mark the relevant field, that should be filtered.

When you write a filter code, it works with one page, but the link will always be the same: mywebsite/results

Of course it’s possible to set filtervalues to the link, but I really don’t know how to do that.

Here are two pictures of the same DB. It’s a test DB before importing the whole data. In red, the columns I would like to filter.

Yes the link should be mywebsite/results (+filters)

It seems difficult but is it not supposed to be a basic action / need to do with a DB ?

If it’s really impossible, is there a way to add a dropdown filter on the category page to let the users do the filtering ?

Thanks.

Okay, you can do both.

  1. The user filter it itself

  2. The user press the button and then the filter works automatically

But if you have so much different results, isn’t it better to set a normal filter ?

I think a filter like this would be easier to handle, a user can go on the page and search what he wants.

With buttons he can only search what set in the code.

So tell me, do you want buttons or a user filter, then I send you some codes.
Can you code a little bit ?

Yes I understand code and can use it a little bit too.

The idea of making automatic filter is to improve the user experience directly from the homepage. On my screenshot, they could click “courage” and be directly redirected to the category page showing the books tagged with “courage”. Then they don’t need to go to the page and filter by their own.


Maybe some will want to filter and then two solutions could coexist :wink:

So if possible let’s go for both :slight_smile:

Thanks Nick.

So you need 2 codes.
One for your homepage and one for your results page.

The problem is that the button would need a value and you can’t give the button a value.

So one idea would be to make a unvisible text input and put in a text, when you klick on the button (on both pages with the same name).

Homepage:

import { session } from 'wix-storage';
import wixLocation from 'wix-location';

function button_click(event) {
    session.clear();
    
    //"#textinput" setvalue "courage"
    // you have to find a code for this
    
 let value = $w("#textInput").value;

    session.setItem("SearchWord", value);
wixLocation.to(`/yourResultPage`);
}

Result page:

import wixData from 'wix-data';
import { session } from 'wix-storage';

$w.onReady(function () {

 var sameWord = session.getItem("courage");

    $w("#textInput").value = sameWord;
    
    session.clear();
   
let filter = wixData.filter(); 

if ($w("#textInput").value === "courage") {
filter = filter
     .contains('courageDBfieldkey', $w("#textInput").value)
     }
    $w('#dataset1').setFilter(filter)
})

This is the logic of the code.

So when you press the button, you give a textInput a value, save it in session and redirect to your results page.

Then Wix imports the saved value and imports it into another textInput.

If the value of the textInput and the value of the filter you want to use are the same, the filter is executed and shows all results that have the word “courage” in the selected fieldkey.

I just wrote this code, so it can be, that that a bracket is missing or there’s another little mistake.

So search for a code for your button please and try this code.
Then tell me your result please.
I’m here for you tomorrow again :smiley:

Thanks ! :grinning:

I’ll check that later tonight and let you know for tomorrow :wink: :nerd_face: :grinning:

Ok so I tried but there seems to be mistake somewhere.

On my homepage I created the button and a text input. I added your code and added the code to set the value of the text input (not sure of this code)

On my category page (named Sarabande), I copied your other code and added a text input too with the same value (no code here for the value).

When I click the button on the homepage, I go to the category page but there is no filter for “courage”. Everything is shown.

Maybe I’m missing something. :thinking:

The error is in line 23. You haven’t defined which field your code should filter.
Go to your database, go to “Themes” filed and go to settings: here a screenshot

There your find your field-key. Paste it in line 23 instead of “courageDBfieldKey”

Then it should work :grinning:

Hello,

I changed “courageDBfieldKey” with the field key “themes” but it stil doesn’t work :S

Maybe de url here is not good :

session.setItem("SearchWord", value);
wixLocation.to(`/sarabande`);
}

I’m in draft mode and nothing is published yet…

Hey,
for me the code works, I just fried the filter:

import wixData from 'wix-data';

function Filter(title) {
 let filter = wixData.filter()

 if ($w("#input1").value === "Meran") {
        filter = filter
            .contains("place", $w("#input1").value)

    }

    $w('#dataset1').setFilter(filter);
}

is courage written as text, or is it just a placeholder ?
Click on the field, then you can see it.

When I select it, it disappear and I can write. So placeholder ?

Yeah, go to the input settings and write something in the placeholder like “aaaaaa”


The problem is, that “courage” doesn’t get importet from your homepage.

On your homepage:

line 29: delete the (…) from courage → $w(“#textinput”).value = “courage”;
line 29: you need 3 ===, so write → $w(“#textinput”).value === “courage”;

I made the changes but still no luck :S

Here is what I have so far

Homepage

Result page