Modify Taxonomy Drop-down Options

This short script allows you to modify some of the options of each of the Taxonomies displayed in GEO my WP search forms.
Below is the filter that is going to be used is in order to do that:

apply_filters( 'gmw_pt_dropdown_taxonomy_args', $args, $gmw, $taxonomy); ?>

which can be found in geo-my-wp/plugins/posts/includes/gmw-pt-search-functions.php line 100.

The arguments provided by the filter are:

  1. $args - the default arguments pass into the function
  2. $gmw - the form's settings
  3. $taxonomy - the taxonomy value

GEO my WP uses the function wp_dropdown_categories in order to display a taxonomy drop-down select box.

Below is the complete list of the arguments that the function provides and that you can modify using the filter above:

$args = array(
	'show_option_all'    => '',
	'show_option_none'   => '',
	'orderby'            => 'ID', 
	'order'              => 'ASC',
	'show_count'         => 0,
	'hide_empty'         => 1, 
	'child_of'           => 0,
	'exclude'            => '',
	'echo'               => 1,
	'selected'           => 0,
	'hierarchical'       => 0, 
	'name'               => 'cat',
	'id'                 => '',
	'class'              => 'postform',
	'depth'              => 0,
	'tab_index'          => 0,
	'taxonomy'           => 'category',
	'hide_if_empty'      => false,
        'walker'             => ''

Please refer to the function's original page for more information about each of the arguments.

Using the filter

Let say for example that we want to modify the default title of a taxonomy which is "-- All --" to our own custom title. In this example we want to modify the title only for the form with ID 1 and only for the taxonomy "category".
For that we will use the function below ( the function should be placed in the functions.php file of your theme ):

function gmw_modify_taxonomy( $args, $gmw, $taxonomy ) {
	//check that we are within form ID 1, otherwise do nothing
	if ( $gmw['ID'] != 1 )
		return $args;
	//check that this is 'category' taxonomy, otherwise do nothing
	if ( $taxonomy->name != 'category' )
		return $args;
	//modify the show_option_all of the taxonomy which is responsible 
	//of the default value of the drop-down select box
	$args['show_option_all'] = ' All Categories';
	//return the modifyed args
	return $args;

add_filter( 'gmw_pt_dropdown_taxonomy_args', 'gmw_modify_taxonomy', 10, 3 );