Setup

Welcome to the official documentation for WP Advanced Search, the most powerful solution for building advanced search forms in WordPress. Here you will find all you need to know about installing the framework and configuring your own advanced search forms.

Tip: You may find that there is a lot of information here to digest. After installing WPAS, it may be most helpful to check out the Demos section for a variety of example implementations, each of which includes source code to help you get started.

Technical Requirements

The latest version of WP Advanced Search requires PHP version 5.3 or newer, and WordPress version 4.1 or newer. It is probably also worth mentioning that this framework is intended for use by experienced developers: if you are not comfortable with the in’s and out’s of PHP programming and syntax, you may have difficulty using this product.

Installation

  1. To install WP Advanced Search, first download & extract the source code to a new folder named “wp-advanced-search” inside your WordPress theme directory (ie /wp-content/themes/twentytwelve/wp-advanced-seach).
  2. Add the following at the top of your theme’s functions.php file:
require_once('wp-advanced-search/wpas.php');

Note: The framework assumes by default that it is located in the root of your theme folder, as shown above. If you want to place the directory in a subfolder, you can specify its location by setting the following in your wp-config.php file:

define('WPAS_URI', get_stylesheet_directory_uri() . '/path/to/wp-advanced-search');

Creating & Configuring Forms

To create a new search form, start by defining a new function in your
functions.php file:

function my_search_form() {
    $args = array();
    $args['wp_query'] = array('post_type' => 'post',
                              'posts_per_page' => 5);
    $args['fields'][] = array('type' => 'search',
                              'title' => 'Search',
                              'placeholder' => 'Enter search terms...');
    $args['fields'][] = array('type' => 'taxonomy',
                              'taxonomy' => 'category',
                              'format' => 'select');
    register_wpas_form('my-form', $args);    
}
add_action('init', 'my_search_form');

There are 3 important things to notice here: First, we define an array of arguments called $args which define how our search will work. Next, we call register_wpas_form to register the search form with the framework. The first parameter ‘my-form’ is a name for your form (pick whatever you like), and the second is the $args array we just configured. Finally, we plug the function into WordPress’s ‘init’ hook.

See Configuration & Fields for detailed documentation on configuring your search forms.

To create additional search forms, simply repeat the process above using a new function and form name.

Template Integration

Starting in version 1.4, there are now two ways of displaying search forms in your site’s theme templates:

  • Standard – Normal search functionality with parameters passed in the URL, and page refresh on every submit.
  • AJAX (new) – AJAX-powered search, allowing users to submit queries and browse through results without any page reloading. This method offers a more modern and seamless user experience, and faster response time.