I am attempting to automatically create filters on the front end based on some back-end metaboxes. facet-wp is not being used as it's too much overhead for this simple use.
The fields to be used as filters are flagged as as such using is_filter during the field creation like so:
'fields' => array(
array(
'name' => __('Gender', 'text-domain'),
'desc' => '',
'id' => 'user_gender',
'type' => 'select',
'options' => array(
'Male' => __('Male', 'text-domain'),
'Female' => __('Female', 'text-domain'),
'Diverse' => __('Diverse', 'text-domain'),
),
'attributes' => array(
'required' => true,
'mod_lock' => true,
'is_filter' => true,
),
),
)
Is there a recommended way of selecting all fields that have is_filter set?
This following is working, but maybe there is a better method?
$meta_box_objects = rwmb_get_registry( 'meta-box' )->all();
foreach ( $meta_box_objects as $meta_box_object ) {
$fields = $meta_box_object->fields;
foreach($fields as $field){
if(!empty($field['attributes']['is_filter'])){
//filter field found
$content .= $field['id'].'<br/>';
}
}
}
rwmb_get_registry is not very well documented, so maybe there is a more efficient method?