Search code examples
phpwordpressparent-childcategories

How would I go about showing category parent-child relationship in form field dropdown?


Currently, I'm working on a form for a wordpress site that has a field where a user can select categories. When the field is clicked or typed in, the categories appear in alphabetical order as can be seen in this image.

These categories have parent-child relationships, and I'd like to demonstrate that in the dropdown list. For example, cat-4 in the image above is a child of cat-1, and so ideally cat-4 will appear under its parent and have an indentation or dash before it. Is there any built in or standard way to achieve this in wordpress?


Solution

  • The wp_dropdown_categories() function appears to display hierarchical taxonomies, with child terms being indented according to their parent.