Manually retrieve entries from SearchWP Related
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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