0

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 am looking for any advice on how to achieve this, without a plugin.

I was thinking...Use advanced custom fields to dynamically create new taxonomies. Then I could use those taxonomies to filter my post type.

Any help would be appreciated!

FYI - I am in the early stages and trying to plan this out, I haven't coded anything.

0

Recommended (CPT):

Easier option is to get a custom post type plugin that also has a feature to create custom taxonomies. It is very flexible and let's you configure it precisely you want it to behave like and in the end you can export the code that generates your custom taxonomies and add it to your functions.php so you would save db hits. You can also install ACF to add custom fields to your taxonomy terms.

Using only ACF:

Advanced custom fields itself do not let you create new taxonomies, it can only display your custom input fields on the admin page you want with ease. It also binds that field with the page/term/post/cpt/page/user depending on where you set the field to show up. Ex you create a custom field input named post_subtitle and set it to show up on post edit page, now that field is automatically bind with post type post and it will save field values to wp_postmeta table. If you would add that field to a user page it would save its data to wp_usermeta table.

What you can do with ACF is have a repeater field plugin for it and also options page plugin (they are all included in ACF 5 Pro). Create a repeater field called custom_taxonomies and set that field to show up on options page. That field data will be saved to wp_options table. Now in your functions.php (if you code in theme) loop through that repeater field and register your taxonomies using wp's register_taxonomy method. If your not familiar with wp actions and filters i suggest you get familiar with them, because you have to set your code blocks to run at correct actions for them to show up in wp admin.

Custom code:

If you want to code this yourself you have to keep in mind that taxonomies are not held in database by default but taxonomy terms are. I would go with same approach as woocommerce does, create a new database table where you hold your taxonomy info and load them up every time you need them. Create new admin page and display input field(s) where you can add new taxonomies, edit existing ones etc. It is all doable but this method takes a lot of time and code and is not usually worth it because there are very reliable plugins that can help you inventing the wheel part.

  • I think your second solution makes the most sense for me, I already own ACF Pro. Thinking through this, these are the steps I THINK I need to take. – 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 js to filter results – RiddleMeThis Mar 31 '16 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.