For the code snippet that follows, here’s a high-level overview of how the dropdown filter is added for the Collection taxonomy:
- We extend
wp.media.view.AttachmentFiltersto create our own attachment filter, which is assigned to the
- With our filter variable defined, we extend and override
- We use
wp_localize_script()to make our custom taxonomy’s terms available for use on the frontend.
This code snippet is all you need to add a custom taxonomy dropdown filter. There are annotations to indicate where you need to make changes: