Black Friday & Cyber Monday
50% OFF All plans, upgrades & renewals
View offers

DEVELOPER

Customize taxonomy dropdowns with PHP

Customize GEO my WP taxonomy dropdown labels, sorting and term options, and migrate the legacy taxonomy filter with the correct argument order.

4 min read · Updated December 1, 2026

Use gmw_search_form_dropdown_taxonomy_args to customize a taxonomy dropdown's term-query options and display settings in GEO my WP. This guide covers the current filter and migration from the older gmw_pt_dropdown_taxonomy_args recipe.

Before adding a filter

Configure a working Posts Locator form with a taxonomy dropdown first. The filter customizes a field that the form already generates; it does not add the field, register a taxonomy or assign terms to posts. See Configure search fields and filters for administrator setup.

The hook suffix follows the field's usage. The name in this guide runs for dropdown usage. A custom field/template using select or multiselect usage reaches the corresponding gmw_search_form_select_taxonomy_args or gmw_search_form_multiselect_taxonomy_args hook instead. It does not automatically customize every taxonomy-field style.

Current hook and argument order

add_filter( 'gmw_search_form_dropdown_taxonomy_args', 'your_callback', 50, 3 );

// Callback arguments, in order:
// $args     Term-query and dropdown settings (array).
// $taxonomy WordPress taxonomy definition (WP_Taxonomy).
// $form     Current GEO my WP form values (array).

Return the full $args array. Use $form['ID'] to scope the change to a form and $taxonomy->name to scope it to a taxonomy. The taxonomy argument is its definition object, not an individual term.

Example: change the label and sorting

This example changes the category dropdown in form 1 to show “All topics,” sort terms alphabetically and include terms without assigned posts. Replace the form ID and taxonomy name for your site.

<?php
/**
 * Customize the category dropdown in GEO my WP form 1.
 *
 * @param array $args Dropdown and term-query arguments.
 * @param WP_Taxonomy $taxonomy Taxonomy being displayed.
 * @param array $form GEO my WP form values.
 *
 * @return array
 */
function mysite_gmw_category_dropdown( $args, $taxonomy, $form ) {
	if ( 1 !== (int) ( $form['ID'] ?? 0 ) || 'category' !== $taxonomy->name ) {
		return $args;
	}

	$args['show_option_all'] = 'All topics';
	$args['orderby'] = 'name';
	$args['order'] = 'ASC';
	$args['hide_empty'] = false;

	return $args;
}

add_filter( 'gmw_search_form_dropdown_taxonomy_args', 'mysite_gmw_category_dropdown', 50, 3 );

Place the code in your own plugin, an appropriate code-snippet tool or a child theme's functions.php. Omit the opening PHP tag when adding it to an existing PHP file. Keep the callback name unique.

Options and limits

  • show_option_all changes the empty-selection option text.
  • orderby and order control term ordering.
  • hide_empty controls whether unused terms can appear.
  • include or exclude can limit the available term IDs. For example, $args['exclude'] = [ 12, 34 ]; excludes those example term IDs. Replace them with IDs from your site; use one strategy at a time and inspect the resulting list.
  • The helper also forwards exclude_tree, hierarchical, child_of and parent into its term query. Display settings such as show_count and depth are used separately while rendering.

GEO my WP selects a subset of these arguments for its term lookup and renders its own select element and category walker. The old recipe's claim that all wp_dropdown_categories() arguments apply is outdated. Do not assume unrelated WordPress dropdown arguments or every get_terms() argument will be forwarded. See the WordPress term-query reference for the meaning of the forwarded query options.

Hiding terms in a dropdown changes the interface. It is not an authorization rule and does not prevent a visitor from submitting a different term value. Enforce access and query restrictions separately when your application requires them.

Migrate the older taxonomy recipe

The deprecated gmw_pt_dropdown_taxonomy_args filter still runs after the current filter. Its first three arguments are $args, $form, $taxonomy. The current filter uses $args, $taxonomy, $form: the second and third arguments are reversed.

Replace the old registration with the current hook and update the callback parameter order together. Preserve the return array and your form/taxonomy checks. Do not leave both registrations active for the same customization, because the later deprecated callback can overwrite the current filter's changes.

The old source path plugins/posts/includes/gmw-pt-search-functions.php is obsolete. The current implementation is GMW_Search_Form_Helper::get_taxonomy_element() in includes/template-functions/class-gmw-search-form-helper.php.

Verify the dropdown

  1. Open the intended form and check the label, order and visible terms.
  2. Check another form and another taxonomy to confirm they retain their original options.
  3. Select an available term, submit the form and verify the expected results.
  4. If the customization is absent, check the field's usage/hook name, form ID, taxonomy name and any remaining deprecated callback.

For broader runtime form settings, see gmw_default_form_values. For unexpected search output, follow Search filters return unexpected results.