Skip to content

Instantly share code, notes, and snippets.

@ntwb
Created September 26, 2014 07:13
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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' );
@pazzaglia
Copy link

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
Copy link

chazzzzy 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
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