Filter blog by category - Editor X

Hi All, I’ve successfully filtered a dynamic page with the Dataset and dropdown. However, the client has found the Dynamic pages tricky to edit, being Editor X. I was hoping I could just use blogs and filter by Categories. However, you cannot filter by blog Category Reference on a dropdown.

So, I’m hoping this is something Velo could help with. I’ve watched a few tutorials but it really confuses me. To put it simply, I want 1 dropdown to filter by Blog Category.

Any help would be much appreciated, I am a total code noob.

https://in-good-company.editorx.io/arklow-town/nature-and-outdoors

This is the code I’ve got so far:

import wixData from ‘wix-data’ ;

export function button13_click(event) {
search();
}

function search() {

wixData.query( "Blog/Posts" ) 
    .contains( "categories" , String($w( "#dropdown1" ).value)) 
    .and(wixData.query( "Blog/Posts" ).hasAll( "hashtags" , String($w( "#dropdown2" ).value))) 

    .find() 
    .then(results => { 
        $w( "#repeater3" ).data = results.items; 
    }); 

}

console.log()

However, I get this error in the Console Log:
Unknown error. Request ID: 1613829589.352897984355331217. Message: Internal server error

Try your luck here…

Perhaps it’s a better place to find an answer for your issue.

@russian-dima Thank you, that seems to be for the Forum App. Maybe I’ll message support again. I thought adding a dropdown filter would be simple >_<

@info50984 You should note that the Dropdown value is already a String, and there’s no need to convert it to a String.

Are you sure that both Dropdowns actually have a value?

Hi @yisrael-wix , thank you for getting back to me, it’s much appreciated. Yes, they have a value when I check the dropdown. To be honest, the code I used is from following a tutorial, that says copy this code, change this value. So I’m not really sure what it does.

I’m still waiting on Editor X to add the search function so I can have 1 category dropdown and 1 search for hashtags. That’s how I’m hoping it would work anyway.

The main reason for this is that the client wants to add new listings themselves but they got confused with datasets, so I decided to use blogs to keep it simple for them.

Well, “copy this code, change this value” is not exactly the best way to work. As you said, “So I’m not really sure what it does.”

With that in mind, it seems that what you are missing is the Repeater onItemReady() function. You should put that in the page’s onReady() function (which you seem to have deleted). The Repeater onItemReady() function sets the fields of the Repeater Item so it can be displayed. Keep in mind, you will need to do this in code, and you’ll need to understand what you’re doing.

You might want to try populating the Repeater with a Dataset instead. Using a Dataset you will not need to add an onItemReady() function since all of the elements in the Repeater are connected to the Dataset. See the article Displaying Collection Content in a Repeater to see how that’s done.

Yes, I totally understand that. I’ve never used this type of code before, so it’s all very new to me.

The repeater is currently being populated with the Posts Dataset, as I thought I could originally do this by adding a category dataset, the no-code way but it wouldn’t let me select category contains. However, it does state on collection fields I can filter by contains: Can be filtered : hasAll, hasSome, contains

So the code I’m using is actually trying to do what the Dataset is doing? Maybe that’s part of the issue.

Apologies, maybe I wasn’t very clear in the beginning.