Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search only topics not forum / replies


  • pluus
    Participant

    @pluus

    Hi,

    I’d like to have a search box that only searches topics but forum & replies. What file or hooks should I change? Please enlighten me 🙁 Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)

  • pluus
    Participant

    @pluus

    Hmph… okay… I’ve noticed that /plugins/bbpress/includes/search/template.php is actually responsible for that feature:

    
    function bbp_has_search_results( $args = '' ) {
    	global $wp_rewrite;
    
    	/** Defaults **************************************************************/
    
    	$default_post_type = array( bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type() );
    
    	// Default query args
    	$default = array(
    		'post_type'           => $default_post_type,         // Forums, topics, and replies
    		'posts_per_page'      => bbp_get_replies_per_page(), // This many
    		'paged'               => bbp_get_paged(),            // On this page
    		'orderby'             => 'date',                     // Sorted by date
    		'order'               => 'DESC',                     // Most recent first
    		'ignore_sticky_posts' => true,                       // Stickies not supported
    		's'                   => bbp_get_search_terms(),     // This is a search
    	);
    
    

    So, changing ‘post_type’ => $default_post_type to ‘post_type’ => bbp_get_topic_post_type() works. However, it’s not clearly the best practice to modify the plugin directly anyother way to override this?


    Robin W
    Moderator

    @robin-w

    yes put this in your functions file – untested but should work

    add_filter ('bbp_before_get_search_terms_parse_args', 'pluus_amend_search') ;
    
    function pluus_amend_search ($args) {
    	$args['post_type'] =  bbp_get_topic_post_type() ;
    return $args ;
    }

    pluus
    Participant

    @pluus

    Whoa! Thanks!


    Robin W
    Moderator

    @robin-w

    great – glad you are fixed !

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar