Dynamic Field Sorting for WordPress ACF
A site my employer has uses the Advance Custom Fields plugin for WordPress. They use the plugin to create custom post types which they use for creating product pages. This plugin allows you to create fields that are attached to the custom post type and gives users the ability to enter posts with custom fields. The job here was to create pages that list out, or filter, product posts based on the value of the custom fields.
The issue was that the two fields, “Categories” and “Sub Categories” didn’t have any correlation other than the products they were attached to. In other words, I wasn’t able to actually pull what sub categories were associated with categories because these fields weren’t tied together. The solution involved loading up temporary arrays and sorting and filtering those arrays.
The result was a page that allows sorting based on url variables