Skip to content

Instantly share code, notes, and snippets.

@searchwpgists
Created April 12, 2022 16:31
Show Gist options
  • Save searchwpgists/b87525b4a4b1b0636a14c8f3c531da0b to your computer and use it in GitHub Desktop.
Save searchwpgists/b87525b4a4b1b0636a14c8f3c531da0b to your computer and use it in GitHub Desktop.
<?php
//@link https://searchwp.com/documentation/classes/swp_query/
global $post;
$swp_query = new SWP_Query( [
's' => 'coffee', // Search query.
'engine' => 'default', // Engine name.
] );
if ( $swp_query->have_posts() ) {
while ( $swp_query->have_posts() ) :
$swp_query->the_post();
?>
<div class="search-result">
<h3><a href="<?php echo get_permalink(); ?>">
<?php the_title(); ?>
</a></h3>
<?php the_excerpt(); ?>
</div>
<?php
endwhile;
wp_reset_postdata();
} else {
?>
<p>No results found.</p>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment