My overall goal is to have a custom post type and on the archive page have several different filters in the sidebar, like on a lot of ecom sites. I think this would normally be done in WordPress using several taxonomies. In my case I need these filters to be dynamic, meaning the client can log-in to the admin and add filters and options under those filters.
I was thinking…Use ACF to dynamically create new taxonomies. Then I could use those taxonomies to filter my post type. BUT I can’t find any info on that and don’t know if thats even possible.
Any help would be appreciated!
FYI – I am in the early stages and trying to plan this out, I haven’t coded anything.
– Add an options page under the CPT with filters
– Add custom fields in a repeater on that options page to add filters
– Use those custom fields to dynamically create taxonomies in functions.php
– Now when creating posts we can pick what taxonomies apply to that post
– On the frontend pull in all taxonomies and use jquery to filter results
Does this sound like a good game plan?
There isn’t any reason why the values need to be taxonomies (or terms). They can be custom fields. Creating this type of filtering (search) system is a complicated process that can take many hours of development. There are existing plugins that can do this. Search for things like “Parametric” or “Faceted” search for WP. You’ll find several plugins and some explanations of how to accomplish it. I’ve used https://facetwp.com/ for this.
Thanks for the reply. I thought about using the custom fields, I would prefer this method, similar to https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/ tutorial but I need the client to be able to add/edit filters on the go. I’m not sure how I would do that with this approach. I don’t want the client messing around in ACF.
I appreciate the suggestion of the plugins, the one you linked looks nice. I have a big amount of time set aside for coming up with a custom solution, so I’d like to stick with that, at least for now.
Allowing the client to add additional filters on the fly is going to be your biggest hurdle and that won’t matter if you’re using custom fields or taxonomies/terms to do it.
You could create an options page that lets them define the “parameters” and then you can dynamically generate and ACF field group based on the values entered into these options. I think this would be better than dynamically generating a taxonomy based on them, but you could probably do that as well.
Like I said, your biggest hurdle will be dynamically generating the filter form and the results dynamically based on what the client has created. There aren’t even any examples of this that I know of. I’ve used (and build) a lot of search tools and I’ve never seen anything that would allow this.
Crap, I didn’t mean to mark your last comment as the solution, lol, o-well you have been helpful! Thanks for all the feedback. I think your right, I haven’t been able to find an example of this either. Doesn’t Woo-Commerce do this in a sense? I will keep digging/thinking about it.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.