Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active April 19, 2017 17:56
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 jchristopher/1a83ac8723041b972c62 to your computer and use it in GitHub Desktop.
Save jchristopher/1a83ac8723041b972c62 to your computer and use it in GitHub Desktop.
The most basic implementation of SWP_Query
<?php
/**
* Use SearchWP's SWP_Query to perform a search using the default engine
*/
$swp_query = new SWP_Query(
array(
's' => 'coffee', // search query
)
);
if ( ! empty( $swp_query->posts ) ) {
foreach( $swp_query->posts as $post ) : setup_postdata( $post ); ?>
<div class="search-result">
<h3><a href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</div>
<?php endforeach; wp_reset_postdata();
} else {
?><p>No results found.</p><?php
}
@acksee
Copy link

acksee commented Apr 19, 2017

Is there a way to do an empty search?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment