WordPress Advanced Search – Setting up Arguments
-
I’m using the WordPress Advanced Search plugin, which I think is quite a cool plugin, but I’m having some difficulties setting up the form the way I want it to work.
I want the form to have a general search box, select menus and radio buttons. The general search should find posts by custom taxonomies, custom fields and general keywords. Currently it only finds posts by the title, when I used custom fields values nothing is return, the same for taxonomies.
The select menus allow me to filter the results by taxonomy, no problem there. However, I have three select menus, one for groups (taxonomy) and the other two for country and city, both custom fields. These work but I don’t know how to auto populate the select menu options with custom field values that currently exist on the site. For example, if I have someone living in Bangkok, if I manually input Bangkok into the values it finds Bangkok, however this is obviously no good when new members will be joint the site.
The radio buttons just order the results by company name, country, or city. This works fine.
Here are the form args so far:
<?php $args = array(); $args['wp_query'] = array( 'post_type' => array('members_directory'), 'posts_per_page' => 10, 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => 'member_company' ); $args['form'] = array( 'action' => 'http://localhost:8888/member-directory/#aio-directory-results', // don't forget to change this url 'method' => 'GET', 'id' => 'directory-search', 'name' => 'wp-advanced-search', 'class' => 'directory-search-form', ); $args['fields'][] = array( 'type' => 'search', 'placeholder' => 'Search by Keyword, City, or Country', 'class' => 'form-control aio_top_search', 'id' => 'aio_directory_search', ); // Select Menus for searching by group, country, city $args['fields'][] = array( 'type' => 'taxonomy', 'taxonomy' => 'aio_groups', 'values' => array('' => 'Filter by group', 'projects' => 'Projects', 'commercial' => 'Commercial', 'exhibitions' => 'Exhibitions', 'perishables' => 'Perishables', 'removals' => 'Removals'), 'class' => 'form-control aio-select', 'format' => 'select', ); $args['fields'][] = array( 'type' => 'meta_key', 'meta_key' => 'member_country', 'class' => 'form-control aio-select', 'values' => array('' => 'Filter by country', 'Thailand' => 'Thailand'), 'format' => 'select', 'meta_query' => array( array( 'key' => 'member_country', 'value' => '', 'compare' => 'IN', ) ) ); $args['fields'][] = array( 'type' => 'meta_key', 'meta_key' => 'member_city', 'values' => array('' => 'Filter by city', 'Bangkok' => 'Bangkok', 'London' => 'London'), 'class' => 'form-control aio-select', 'format' => 'select', 'meta_query' => array( array( 'key' => 'member_city', 'value' => '', 'compare' => 'IN', ) ) ); $args['fields'][] = array( 'type' => 'html', 'value' => '<h5>Order by: </h5>' ); // Radio buttons for ordering the results $args['fields'][] = array( 'type' => 'orderby', 'format' => 'radio', 'class' => 'aio-radio-btns', 'title' => 'Order By', 'orderby_values' => array( 'member_country' => array('label' => 'Country', 'meta_key' => true, 'orderby' => 'meta_value'), 'member_city' => array('label' => 'City', 'meta_key' => true, 'orderby' => 'meta_value'), 'member_company' => array('label' => 'Company Name', 'meta_key' => true, 'orderby' => 'meta_value'), ) ); $args['fields'][] = array( 'type' => 'submit', 'value' => 'Search the directory »', 'class' => 'directory-btn' ); $search_directory = new WP_Advanced_Search($args); // echo '<pre>', var_dump($search_directory), '</pre>'; ?>So my problems are as follows:
1) I need the general search box to find posts based on all information – keywords, taxonomy terms, custom field values.
2) I need to auto populate the select menus with countries and cities that are currently in existence on the site.
I’m sure it’s just a fundamental misunderstanding of how this works. My PHP skills are fairly basic so I’d appreciate some help from the community. There doesn’t seem to much documentation on WPAS, other than their site and the github forums. And I’m not always savvy enough to understand what I should do with out a concrete example.
Thanks
The topic ‘WordPress Advanced Search – Setting up Arguments’ is closed to new replies.