When creating filters in the builder, the first step is to choose the data source. By default, FiboFilters add basic WooCommerce data to the source list, such as:
- categories
- tags
- attributes
- price
- stock status
- ‘On sale’ information
Plugin integrations can add new records to the source list. For example, the ACF integration adds custom fields related to products as a new data source. Another example is the ‘Brands’ value added to the sources.
However, some sources, such as taxonomies or custom fields (aside from those mentioned before) can’t be added automatically. To add them to the list, use these PHP snippets.
Support for custom taxonomies
Let’s assume that a new taxonomy, “Manufacturer”, has been registered. For this taxonomy to be added to the “Data source” list, you need to use this PHP snippet:
add_filter( 'fibofilters/filters/custom_sources/taxonomies', function ( $taxonomies ) { $taxonomies[] = [ 'label' => 'Manufacturer', 'taxonomy' => 'manufacturer', ]; return $taxonomies; } );
If the snippet is inserted correctly, a new position will be added to the “Data source” list: “Manufacturer”.
Support for custom fields
Every custom field can be set as a filter’s source data. However, these fields must be first registered – this process is not done automatically. Our integrations with third-party plugins, such as Advanced Custom Fields, are the exception. In this case, custom fields will be immediately selectable as a data source.
To make any custom field selectable from the Data source dropdown, you need to register them with this PHP snippet. Let’s assume that two custom fields were created – “Feature” and “Scale”. Their values are saved in the postmeta
table, where the meta_key
s are feature
and scale
, respectively.
add_filter( 'fibofilters/filters/custom_sources/custom_fields', function ( $custom_fields ) { $custom_fields[] = [ 'field_slug' => 'feature', // meta_key 'label' => 'Custom field: Feature', 'label_front' => 'Product Feature', ]; $custom_fields[] = [ 'field_slug' => 'scale', // meta_key 'label' => 'Custom field: Scale', 'label_front' => 'Product Scale', ]; return $custom_fields; } );
If the snippet is inserted correctly, two new positions will be added to the “Data source” list: “Custom field: Feature” and “Custom field: Scale”.