How to add your custom fields to the search widget

With the new remastered search widget and shortcodes you can now add additional search parameters.

Add custom search parameters to EPL - Search Widget

Add your options to the search widget

The first filter will add your options to the search widget.

// Add Custom Options to Search Widget
function my_epl_custom_search_fields_callback( $array ) {


	$array[] = array(
		'key'     => 'custom_search_checkbox_1',
		'label'   => __('Custom Checkbox 1','epl'),
		'default' => 'on', // Default display field on or off.
		'type'    => 'checkbox',
		'order'   => '20' // Order in relation to other fields.
	);
	$array[] = array(
		'key'     => 'custom_search_checkbox_2',
		'label'   => __('Custom Checkbox 2','epl'),
		'default' => 'on', // Default display field on or off.
		'type'    => 'checkbox',
		'order'   => '21', // Order in relation to other fields.
	);
	$array[] = array(
		'key'     => 'custom_search_checkbox_3',
		'label'   => __('Custom Checkbox 3','epl'),
		'default' => 'on', // Default display field on or off.
		'type'    => 'checkbox',
		'order'   => '22', // Order in relation to other fields.
	);
	$array[] = array(
		'key'     => 'custom_search_checkbox_4',
		'label'   => __('Custom Checkbox 4','epl'),
		'default' => 'on', // Default display field on or off.
		'type'    => 'checkbox',
		'order'   => '23', // Order in relation to other fields.
	);
	return $array;
}
add_filter( 'epl_search_widget_fields' , 'my_epl_custom_search_fields_callback' );

Add your options to the displayed search widget

Now you add the search options to the displayed form and control how the search query works.

// Add Custom Search Items to Front End
function my_epl_custom_search_widget_fields_frontend_callback( $array ) {


	// Select Type Example.
	$array[] = array(
		'key'           => 'custom_search_checkbox_1',
		'meta_key'      => 'custom_search_key_1', 
		// When using a taxonomy the meta_key MUST be prefixed with property_taxonomy_name
		'label'         => __('Custom Checkbox 1', 'epl'),
		'type'          => 'select',
		'option_filter'	=> 'custom_search_filter_1',
		'options'       => array(
			'1' => '1',
			'2' => '2',
			'3' => '3',
			'4' => '4',
		),
		'exclude'       => array('land','commercial','commercial_land','business'),
		'query'         => array(
			'query'   => 'meta',
			'key'     => 'custom_property_meta_key_1',
			'type'    => 'numeric',
			'compare' => '<='
		),
		'class'         => 'epl-search-row-full',
		'order'         => 300,
	);


	$array[] = array(
		'key'           => 'custom_search_checkbox_2',
		'meta_key'      => 'custom_search_key_2',
		'label'         => __('Custom Checkbox 2', 'epl'),
		'type'          => 'select',
		'option_filter' => 'custom_search_filter_2',
		'options'       => array(
			'100' => '100',
			'200' => '200',
			'300' => '300',
			'400' => '400',
		),
		'exclude'       => array('land','commercial','commercial_land','business'),
		'query'         => array(
			'query'		=> 'meta',
			'key'		=> 'custom_property_meta_key_2',
			'type'		=> 'numeric',
			'compare'	=> '<='
		),
		'class'         => 'epl-search-row-half',
		'wrap_start'    => 'epl-search-row custom_search_class_1',
		'order'         => 310,
	);


	$array[] = array(
		'key'           => 'custom_search_checkbox_3',
		'meta_key'      => 'custom_property_meta_key_3',
		'label'         => __('Custom Checkbox 3', 'epl'),
		'type'          => 'select',
		'option_filter' => 'custom_search_filter_3',
		'options'       => array(
			'100000' => epl_currency_formatted_amount('100,000'),
			'200000' => epl_currency_formatted_amount('200,000'),
			'300000' => epl_currency_formatted_amount('300,000'),
			'400000' => epl_currency_formatted_amount('400,000'),
		),
		'exclude'       => array('land','commercial','commercial_land','business'),
		'query'         => array(
			'query'		=> 'meta',
			'key'		=> 'custom_property_meta_key_3',
			'type'		=> 'numeric',
			'compare'	=> '<='
		),
		'class'		=> 'epl-search-row-half',
		'wrap_end'	=> true,
		'order'         => 320,
	);
	// Checkbox Type
	$array[] = array(
		'key'           => 'custom_search_checkbox_4',
		'meta_key'      => 'custom_property_meta_key_4',
		'label'         => __('Custom Checkbox 4', 'epl'),
		'type'          => 'checkbox',
		'option_filter' => 'custom_search_filter_4',
		'exclude'       => array('land','commercial','commercial_land','business'),
		'query'    => array(
			'query'   => 'meta',
			'compare' => 'IN',
			'value'   => array( 'yes', '1' ),
		),
		'class'		=> 'epl-search-row-half',
		'wrap_start' => 'epl-search-row epl-search-other--custom',
		'order'         => 330,
	);
	// Checkbox Type as key is the same as custom_search_checkbox_4 these will be grouped.
	$array[] = array(
		'key'           => 'custom_search_checkbox_4',
		'meta_key'      => 'custom_property_meta_key_5',
		'label'         => __('Custom Checkbox 5', 'epl'),
		'type'          => 'checkbox',
		'option_filter' => 'custom_search_filter_5',
		'exclude'       => array('land','commercial','commercial_land','business'),
		'query'    => array(
			'query'   => 'meta',
			'compare' => 'IN',
			'value'   => array( 'yes', '1' ),
		),
		'class'		=> 'epl-search-row-half',
		'wrap_end'	=> true,
		'order'         => 340,
	);
	return $array;
}
add_filter( 'epl_search_widget_fields_frontend' , 'my_epl_custom_search_widget_fields_frontend_callback' );