Skip to content

Instantly share code, notes, and snippets.

@ntwb
Created September 26, 2014 07:13
Show Gist options
  • Save ntwb/7363a1de1184d459f0c3 to your computer and use it in GitHub Desktop.
Save ntwb/7363a1de1184d459f0c3 to your computer and use it in GitHub Desktop.
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' );
@evanheisler
Copy link

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.

@SanthoshKumarD
Copy link

This is exactly what I was looking for. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment