Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bbPress - Include Topics and Replies in WordPress Search Results
<?php
/*
Plugin Name: bbPress - Include Topics and Replies in WordPress Search Results
Plugin URI: https://gist.github.com/ntwb/7363a1de1184d459f0c3
Description: bbPress - Include Topics and Replies in WordPress Search Results
Version: 0.1
Author: Stephen Edgar - Netweb
Author URI: http://netweb.com.au
*/
/**
* Include bbPress 'topic' custom post type in WordPress' search results
*/
function ntwb_bbp_topic_cpt_search( $topic_search ) {
$topic_search['exclude_from_search'] = false;
return $topic_search;
}
add_filter( 'bbp_register_topic_post_type', 'ntwb_bbp_topic_cpt_search' );
/**
* Include bbPress 'reply' custom post type in WordPress' search results
*/
function ntwb_bbp_reply_cpt_search( $reply_search ) {
$reply_search['exclude_from_search'] = false;
return $reply_search;
}
add_filter( 'bbp_register_reply_post_type', 'ntwb_bbp_reply_cpt_search' );
@pazzaglia

This comment has been minimized.

Copy link

commented Dec 6, 2014

This is EXACTLY what I need - but can you point me to instructions on how to implement it? Should I drop this file in my plug-ins folder? Copy the code into my functions file? Sorry for being so dense and thank you for tackling this!!

Ciao,

L

@chazzzzy

This comment has been minimized.

Copy link

commented Jan 3, 2015

If you add the following to the above code it will also search for Forum Titles.. which the above code doesn't include:

/**

  • Include bbPress 'forum' custom post type in WordPress' search results */

function ntwb_bbp_forum_cpt_search( $forum_search ) {
$forum_search['exclude_from_search'] = false;
return $forum_search;
}
add_filter( 'bbp_register_forum_post_type', 'ntwb_bbp_forum_cpt_search' );

@evanheisler

This comment has been minimized.

Copy link

commented Mar 4, 2015

Thanks so much for this snippet. Very helpful, although it does not appear to respect a forums' privacy. If the content cannot be viewed by the current user, it probably shouldn't appear in search results.

I just started looking at this, but I imagine we could grab the parent forum and check to see if the current user has permission to view it.

EDIT: Sorry, just realized that all this is doing is making the post types available to search and has nothing to do with the results. Carry on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.