Instantly share code, notes, and snippets.

Embed
What would you like to do?
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