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 81-90 of 82 results

values

Post Type: Parameter    Date added: February 19, 2013

A custom array of key => value pairs, used for populating select fields, radio buttons and checkboxes.

wp_query

Post Type: Parameter    Date added: June 28, 2015

Defines the default WP_Query arguments for a search instance. Any arguments accepted by the native WP_Query can be included in this array.