facetwp_excluded_custom_fields
Overview
In FacetWP’s admin area, FacetWP uses the FWP()->helper->get_data_sources() function to fetch existing custom fields, to show them in each facet’s “Data source” setting dropdown and in the dropdown used to add new Listing Builder listing items.
In some cases, you may want to prevent one or more custom field(s) from showing up in these dropdowns. This hook can be used to exclude specified fields by an exact match of the field name.
Note that there is also a sister hook, facetwp_excluded_custom_fields_like, with which you can filter out fields with a partial match, e.g. for a range of fields that have a hashed part of the name.
Alternatively, you could use the facetwp_facet_sources hook that runs after both the facetwp_excluded_custom_fields and facetwp_excluded_custom_fields_like hooks, after they are fetched from the database. That hook can be used to customize the entire list of data sources, including taxonomies and fields from other plugins that FacetWP integrates with, and their labels. It also lets you add new fields and field groups, or change the order of the groups in the dropdown.
Parameters
- $fields | array | An array of field names to exclude
Example
The following example removes the my_custom_field from the facets’ and Listing Builder listing items’ Data source dropdowns:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_filter( 'facetwp_excluded_custom_fields', function( $fields ) { $fields[] = 'my_custom_field'; // Exclude 'my_custom_field' from all data sources dropdowns return $fields; });