I'm working on a directory which I've created in Wordpress. The directory lives as a custom post type called "agents" and has it's own taxonomy called "agent_location". Each agent has multiple "agent_location" terms added to their listing. Each agent_location term is only connected to one "agent". Each agent_location is the beginning of a UK postcode. For example "AB1 1" or "AB11 3" etc.
I'm using WPAS Wordpress Advanced Search (http://wpadvancedsearch.com/) to create the search forms. I would like the end user to be able to type their entire postcode for example AB1 1AA and be presented with the agent post that has the term "AB1 1" and not the agent post that has "AB11 3" listed. Essentially the search needs to ignore the last 2 digits of any search entered. Currently the form I've created looks like this:
function agents_search_form() {
$args = array();
$args['wp_query'] = array('post_type' => 'agents',
'posts_per_page' => -1);
$args['fields'][] = array('type' => 'search',
'title' => 'Search',
'placeholder' => 'Enter search terms...',
'pre_html' => '<div class="hiddenField searchRow"><div class="searchWrap">',
'post_html' => '</div>');
$args['fields'][] = array( 'type' => 'submit',
'class' => 'button',
'value' => 'Search' ,
'pre_html' => '<div class="searchBTNWrap">',
'post_html' => '</div></div>');
$args['fields'][] = array('type' => 'taxonomy',
'taxonomy' => 'agent-location',
'format' => 'text');
register_wpas_form('agents-form', $args);
}
add_action('init', 'agents_search_form');
When you use the form it works perfectly providing you don't include the last 2 digits of your postcode. If you type your entire postcode no search results will be found. I would like help creating a search form that allows users to type their entire postcode into the search and still get a result.
I'm open to the idea of workarounds. Please bare in mind that:
Thanks in advance
I ended up using the Relevanssi plugin - https://wordpress.org/plugins/relevanssi/ and combining it with WPadvancedsearch, it actually works well together and let me do everything I needed.