In my load field function I build and array of CPT -> Tax -> Cats like:
Array(
[CPT] => Array(
[taxonomy] => Array(
[0] => cat 1
[1] => cat 2
[taxonomy] => Array(
[0] => cat 1
[CPT] => etc....
}
with:
function tug415_post_type_categories_to_display_choices($field){
$field['choices'] = array();
$choices = array();
$args = array(
'public' => true,
'_builtin' => false,
);
$output = 'objects';
$post_types = get_post_types($args, $output);
foreach($post_types as $pt){
$args = array(
'object_type' => array($pt->name),
'public' => true,
'_builtin' => false,
);
$output = 'objects';
$taxes = get_taxonomies($args, $output);
foreach($taxes as $tax){
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'taxonomy' => $tax->name
);
$cats = get_categories($args);
$choices[$pt->label][$tax->label] = $cats;
}
}
if(is_array($choices) ){
foreach($choices as $choice){
foreach($choice as $choi){
foreach($choi as $c){
$field['choices'][$c->slug] = $c->name;
}
}
}
}
return $field;
}
add_filter('acf/load_field/name=post_type_categories_to_display', 'tug415_post_type_categories_to_display_choices');
Then the if(is_array($choices) ){...
part put’s all the category values into one ul and displays them, like it should.
What I am trying to do is modify the output so that the user, instead of seeing all the categories in one visual list (clump) be rendered like:
CPT
- Tax1: cat1, cat2, cat3
- Tax2: cat1, cat2
CPT
-Tax1: etc...
Now I can crudely do something like:
$list = '<ul>';
foreach($choices as $choice => $val){
$list .= '<li>'.$choice;
$list .= '<ul>';
foreach($val as $choic => $va){
$list .= '<li>'.$choic;
$list .= '<ul>';
foreach($va as $choi){
$list .= '<li>'.$choi->name;
$list .= '</li>';
}
$list .= '</ul>';
$list .= '</li>';
}
$list .= '</ul>';
$list .= '</li>';
}
$list .= '</ul>';
echo $list;
Then grab this output, use JS to remove the ACF generated ul and replace it with my own but, is there a function or method I’m not finding that allows me to modify the output in my load_filed function and have ACF render it how I define?