Demo (Standard Search)

Search the documentation using this form built with WP Advanced Search!

View the source code

functions.php

<?php function my_search_form() { $args = array(); // Set default WP_Query $args['wp_query'] = array( 'post_type' => array('page', 'field', 'param'), 'orderby' => 'title', 'order' => 'ASC' ); // Configure form fields $args['fields'][] = array( 'type' => 'search', 'placeholder' => 'Enter search terms' ); $args['fields'][] = array( 'type' => 'post_type', 'format' => 'checkbox', 'label' => 'Search by post type', 'default_all' => true, 'values' => array('page' => 'Pages', 'field' => 'Fields', 'param' => 'Parameters') ); $args['fields'][] = array( 'type' => 'orderby', 'format' => 'select', 'label' => 'Order by', 'values' => array('title' => 'Title', 'date' => 'Date Added') ); $args['fields'][] = array( 'type' => 'order', 'format' => 'radio', 'label' => 'Order', 'values' => array('ASC' => 'ASC', 'DESC' => 'DESC'), 'default' => 'ASC' ); $args['fields'][] = array( 'type' => 'posts_per_page', 'format' => 'select', 'label' => 'Results per page', 'values' => array(2=>2, 5=>5, 10=>10), 'default' => 10 ); $args['fields'][] = array( 'type' => 'submit', 'class' => 'button', 'value' => 'Search' ); register_wpas_form('myform'); } add_action('init','my_search_form');

Page Template

<?php get_header(); $search = new WP_Advanced_Search('myform'); ?> <div class="row search-section"> <div id="sidebar" class="large-3 columns"> <?php $search->the_form(); ?> </div> <div class="search-results large-9 columns"> <?php $temp = $wp_query; $wp_query = $search->query(); ?> <h4 class="results-count"> Displaying <?php echo $search->results_range(); ?> of <?php echo $wp_query->found_posts; ?> results </h4> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php $post_type = get_post_type_object($post->post_type); ?> <article> <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> <p class="info"><strong>Post Type:</strong> <?php echo $post_type->labels->singular_name; ?> &nbsp;&nbsp; <strong>Date added:</strong> <?php the_time('F j, Y'); ?></p> <?php the_excerpt(); ?> </article> <?php endwhile; else : echo '<p>Sorry, no results matched your search.</p>'; endif; $search->pagination(); $wp_query = $temp; wp_reset_query(); ?> </div> </div> <?php get_footer(); ?>

Displaying 1-10 of 82 results

action

Post Type: Parameter    Date added: June 24, 2015

Sets the action attribute of a search form. Defaults to the current page URL.

ajax

Post Type: Parameter    Date added: June 28, 2015

Sets AJAX configuration options for a search form. See this page for full documentation.

AJAX Configuration

Post Type: Page    Date added: June 28, 2015

As of version 1.4, search forms can be configured to use AJAX queries instead of the traditional request method. Enabling AJAX for your search can provide users with a more seamless experience by not requiring a full page reload to show results. AJAX configuration is set by extending the ‘form’ section of your arguments array […]

allow_null

Post Type: Parameter    Date added: October 21, 2013

If set to true, this parameter sets the first option of a select field to a null (blank) value. A string can also be passed in to specify a label for the blank value: The above code would create a select menu with “select a category: ” as the default option with no value assigned, […]

attributes

Post Type: Parameter    Date added: April 3, 2014

Allows the addition of custom data attributes to a form field. Attributes must be entered as an array of key => value pairs, as in the example below: The above example will generate HTML for a search field that looks something like this: This featured was added in version 1.2. Currently only works with text, […]

author

Post Type: Field    Date added: February 19, 2013

A field used for searching posts by author.

authors

Post Type: Parameter    Date added: February 19, 2013

auto_submit

Post Type: Parameter    Date added: June 24, 2015

If set to true, the form will automatically submit whenever any field is updated.

button_text

Post Type: Parameter    Date added: June 24, 2015

Sets custom text for the ‘Load more results’ button used with AJAX-enabled forms.

class

Post Type: Parameter    Date added: November 25, 2013

Allows the addition of custom CSS classes to a form field. Any field may use this parameter. Example: Adding a single class Example: Adding a multiple classes using a string Example: Adding multiple classes using an array