This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
This hook can be used to alter the options returned in a Dynamic field that is mapped to a category/taxonomy.
Usage
add_filter('frm_get_categories', 'frm_order_cats', 10, 2); function frm_order_cats($args, $field)
Parameters
- $args (array) - All the parameters used in the WordPress get_categories function.
- $field (array)
Examples
Only include categories with no parent
add_filter('frm_get_categories', 'frm_order_cats', 10, 2);
function frm_order_cats($args, $field){
if($field['id'] == 25){ //change 25 to the ID of your field
$args['parent'] = 0;
}
return $args;
}
Change Order of Categories
This example changes the order of options in a dynamic field set to list categories/taxonomies.
add_filter('frm_get_categories', 'frm_order_cats', 10, 2);
function frm_order_cats($args, $field){
if($field['id'] == 25){ //change 25 to the ID of your field
$args['orderby'] = 'ID';
}
return $args;
}
If your dynamic field is conditional, use the frm_data_sort filter to sort the results by category ID.