Skip to content

Instantly share code, notes, and snippets.

@raideus
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raideus/8124d9c80a4acb755808 to your computer and use it in GitHub Desktop.
Save raideus/8124d9c80a4acb755808 to your computer and use it in GitHub Desktop.
<?php
$args = array();
$args['wp_query'] = array( 'post_type' => array('page', 'field', 'param'),
'orderby' => 'title',
'order' => 'ASC' );
$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' );
$search = new WP_Advanced_Search($args);
?>
<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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment