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 11-20 of 82 results

clear

Post Type: Field    Date added: June 24, 2015

Creates a 'clear' button which clears all field values when clicked.

compare

Post Type: Parameter    Date added: February 19, 2013

Note: If you are using checkbox or multi-select format with a meta_key field, you must set ‘compare’ => ‘IN’ in order for the search to work. Alternatively, if your meta_key was created using the Advanced Custom Fields plugin you may need to use ‘compare’ => ‘LIKE’. See the WP_Query documentation for more information. Using ‘BETWEEN’ […]

Configuration

Post Type: Page    Date added: March 15, 2013

Search forms are configured in WPAS by establishing a set of arguments which define the functionality and behavior of the search. While in the Setup section we covered how to create such a configuration at a high-level, this section provides an in-depth look at the various configuration options available to you. All of the parameters […]

Contributing

Post Type: Page    Date added: March 27, 2015

I am actively seeking contributors for WP Advanced Search to help with maintaining and improving the product. WPAS continues to grow in popularity as the solution of choice for implementing complex search forms in WordPress, and has been deployed on hundreds of websites. Due to other obligations I am not always able to keep up […]

Customizing Appearance

Post Type: Page    Date added: July 22, 2015

There are many built-in features which will allow you to customize the structure and appearance of your search forms. Custom Form Field HTML You can insert custom HTML markup in your form fields by using the pre_html and post_html parameters. These parameters insert HTML directly before and after a form field, respectively. Example: In this […]

data_type

Post Type: Parameter    Date added: October 9, 2013

Used with meta_key fields to specify the type of data stored by the meta_key. Necessary in order to perform proper comparison operations (=, , BETWEEN, etc). Defaults to ‘CHAR’. Note: When attempting to search meta_keys created using the Advanced Custom Fields plugin, you may need to use the special value ‘ARRAY<CHAR>’. Some multi-value ACF fields […]

date

Post Type: Field    Date added: February 19, 2013

Use this field to search results by publication date.

date_format

Post Type: Parameter    Date added: March 19, 2013

date_type

Post Type: Parameter    Date added: February 19, 2013

debug

Post Type: Parameter    Date added: June 24, 2015

Controls debug mode for the search form. When set to true, detailed debug information will be generated on the results page. The debug output contains the following: Errors: If any errors were encountered during the initialization of your search, they will be listed along with their stack traces. WP_Query Arguments: A var dump of the […]