Home Forums General Issues How is the list of taxonomy terms in a select box created?


How is the list of taxonomy terms in a select box created?

  • I have a single select box using a custom taxonomy as a source. Because it is hierarchical, child terms are prefixed with a — to indicate child-parent relationships. These dashes are interfering with the ability to select the box and just type in the name of a term and have snap to that term in the list, so I’d like to strip out the dashes.

    I see in core/fields/taxonomy that the — is added in the acf_taxonomy_field_walker class, but there is no hook to either specifically edit the &mdash to something else or to edit the generated list more generally after it has been built.

    Is there a way to achieve what I’m after?

  • Figured this out thanks to this thread and other help online. Add a new filter:

    add_filter('acf/fields/taxonomy/wp_list_categories', 'md_format_citytax_terms_in_selectbox', 10, 2);

    then use that to replace the walker

    function md_format_citytax_terms_in_selectbox( $args, $field ) {
    	$args['walker'] = new md_taxonomy_field_walker( $field );
        return $args;

    then dupe the walker code from core/fields/taxonomy and replace mdash; with three nbsp; and presto, problem solved.

  • Would be really great if there was a way to simply modify the $indent value in the walker, avoiding all this hackery, but I’m glad it was indeed possible.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.