Created
September 14, 2013 02:46
-
-
Save jchristopher/6558425 to your computer and use it in GitHub Desktop.
Use SearchWP's Supplemental Search Engine feature to limit search results to a single bbPress Forum
This file contains hidden or 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 | |
function myForumIncludeIds( $ids, $engine, $terms ) | |
{ | |
if( $engine != 'my_forum_supplemental_engine' ) | |
return $ids; | |
// set your forum ID | |
$forumID = 900; | |
// retrieve all of the Topic IDs for the Forum | |
$topicsArgs = array( | |
'nopaging' => true, | |
'post_parent' => $forumID, | |
'post_type' => bbp_get_topic_post_type(), | |
'fields' => 'ids' | |
); | |
$topicIDs = new WP_Query( $topicsArgs ); | |
// retrieve all of the Reply IDs from the Topics in the Forum | |
$repliesArgs = array( | |
'nopaging' => true, | |
'post_parent__in' => $topicIDs->posts, | |
'post_type' => bbp_get_reply_post_type(), | |
'fields' => 'ids' | |
); | |
$replyIDs = new WP_Query( $repliesArgs ); | |
// merge the two and use that as our limiter | |
$includeIDs = array_merge( $topicIDs->posts, $replyIDs->posts ); | |
return $includeIDs; | |
} | |
add_filter( 'searchwp_include', 'myForumIncludeIds', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment