Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active July 21, 2017 14:53
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/9ba71c22820361af0b0468e25c4ef527 to your computer and use it in GitHub Desktop.
Save jchristopher/9ba71c22820361af0b0468e25c4ef527 to your computer and use it in GitHub Desktop.
Manually retrieve entries from SearchWP Related
<?php
/*
* Programmatically find Related content from SearchWP Related
*/
// Instantiate SearchWP Related
$searchwp_related = new SearchWP_Related();
// Use the keywords as defined in the SearchWP Related meta box
$keywords = get_post_meta( get_the_ID(), $searchwp_related->meta_key, true );
$args = array(
's' => $keywords, // The stored keywords to use
'engine' => 'default', // the SearchWP engine to use
'posts_per_page' => 3, // how many entries to find
);
// Retrieve Related content for the current post
$related_content = $searchwp_related->get( $args );
// Returns an array of Post objects for you to loop through
print_r( $related_content );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment