Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active December 20, 2015 14:18
Show Gist options
  • Save jchristopher/d6d1a0aec68f3cea6885 to your computer and use it in GitHub Desktop.
Save jchristopher/d6d1a0aec68f3cea6885 to your computer and use it in GitHub Desktop.
<?php
global $post;
$originalPost = $post;
$engine = SearchWP::instance(); // instatiate SearchWP
$supplementalEngineName = 'my_search_engine'; // search engine name
$terms = 'soccer'; // search terms, space separated
$page = 1; // pagination
// perform the search
$posts = $engine->search( $supplementalEngineName, $terms, $page );
// some metrics to build pagination
$foundPosts = $engine->foundPosts;
$maxNumPages = $engine->maxNumPages;
// if we have results...
if( !empty( $posts ) )
{
// loop through results
foreach( $posts as $post ) : setup_postdata( $post ); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
}
$post = $originalPost;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment