Creating a filter for content in wordpress

Joined
Jan 26, 2015
Messages
159
Likes
42
Degree
0
Hello,

I saw the filtering option used on f.ex.: pointblankseo and was wondering how to code something like that up? Any plugins suggestions?

Appreciate your replies!
 
Last edited:
I don't know of any plugins to do this, but I'm sure there are some. I feel like it would depend on how you have your content set up.

A basic example would be adding category and tag filters to the archive page. Here's an example of how I would do it in WordPress:

I would first place each individual piece of filterable content into a WordPress post, and tag them with the appropriate tags and categories. Theoretically, you could create custom taxonomies to increase the complexity of the filters - PBSEO might have three custom taxonomies: "Execution Time", "Link Value", and "Dependencies".

Once my posts are created and tagged, I would create a new PHP function or template to spit out the actual index page. For each filterable taxonomy, I would get all of the taxonomy terms, loop through them, and echo checkboxes for each term with a value corresponding to the taxonomy term's slug. Below these checkboxes, I would just spit out an unfiltered list of the most-recent posts in a uniquely-identified div.

I would then use jQuery to create function that runs whenever one of those checkboxes was toggled. This function would essentially loop through all the checked checkboxes, get the taxonomy term slug that corresponds to each checked checkbox, and send that list of taxonomy term slugs via an AJAX function to another PHP file. AJAX is what is going to let us filter and update the post list without actually refreshing the page.

Anyway, our AJAX function would send the list of slugs of to another PHP file. This file would get the list of slugs from the post data and use them as filter arguments for a new WP Query. It would then loop through the WP Query results and echo each one, ultimately echoing a filtered list of the most recent posts. This list would then get passed back to the AJAX function that initially called it.

Now our AJAX function, which has successfully received a response from our external PHP file, would simply take the content that was returned and use it to overwrite the contents of our uniquely-identified div. Now our div doesn't contain the default unfiltered list of posts, but rather a new list of posts filtered according to our checkboxes. If we then toggled another checkbox, the whole process would run again and our old list of filtered posts would be overwritten by a new list of filtered posts (which takes the checkbox we just toggled into account).

This explanation doesn't cover all of the nuances of building something like this, but it should set you on the right path if you want to give it a shot.
 
There's a bunch of plugins that do this indeed, I've bought a few of them.

There's FacetWP https://facetwp.com/, which should be able to do it. I've bought a few more over the years, but can't remember their names, will have to look it up.
 
Back