Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Jordan Bowman
Jordan Bowman
9,439 Points

Filter posts

I'm making a food blog on Wordpress. For every recipe the owners post, there will be several custom fields where they will indicate (from a few pre–chosen options) how long the recipe takes, what meal it is (breakfast, lunch, dinner, snack), and what course it is (entre, dessert, etc).

I want to create a little box in the sidebar for site visitors where they can choose from the options (maybe in a dropdown list?) under each of the above categories (time required, meal, and course), and then click a "Find" button and all of the recipes that match that request will show up for them.

For example, say a person wants to find a dinner entre that takes 30 min to prepare. They simply choose those options and click "Find" and all the recipes that match that description show up.

This box would have to also allow the user to click options under one or two categories, as opposed to having to click all three.

Any tips for how to pull this off?

1 Answer

Matt Campbell
Matt Campbell
9,767 Points

Just off the top of my head, you need to echo into the query the value of the dropdown box. Best UX is to use Ajax so that you don't have a page load between filtering. That's not overly complicated if you can get your head round WordPress Ajax because it's not the norm. I think it's covered in the new plugin track.

As for the dropdown into the query, that's basic PHP. You can echo in variables and anything you want really, into the query. Just a matter of getting from the dropdown to the query.

Then combine the two and away you go.

Jordan Bowman
Jordan Bowman
9,439 Points

Thanks Matthew – I don't really know anything about Ajax, but I'm sure I could pick it up, I'll look in the plugin track.

Matt Campbell
Matt Campbell
9,767 Points

It just takes a bit of getting used to how the cycle works. WordPress has it built in though which makes it a little more confusing.