Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use SearchWP's Supplemental Search Engine feature to limit search results to a single bbPress Forum
<?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