#1575 closed enhancement (fixed)
Introduce dedicated forum search page with associated template logic
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.3 | Priority: | high |
Severity: | normal | Version: | |
Component: | Component - Search | Keywords: | has-patch needs-testing |
Cc: | jared@…, stephen@…, jmdodd@…, vpundir@…, wordpress@…, pippin@… |
Description
The search field in the twentyten theme does not search for terms inside the forum, but only inside wordpress. Please let me know how to enable searching within the forum.
Attachments (8)
Change History (36)
#2
@
11 years ago
There were complaints of forum topics and replies appearing in the blog search results, so I removed them for now. cnorris23's method above is how to get them back together again.
#3
@
11 years ago
- Milestone changed from Awaiting Review to 2.1
- Type changed from defect to enhancement
Going to move this to 2.1 incase anyone wants to be creative. :)
#5
@
11 years ago
This is a lifesaver, thanks a bunch cnorris23. There's a little correction to the above code, it should be:
function my_add_bbp_to_search( $post_type ) { $post_type['exclude_from_search'] = false; return $post_type; } add_filter( 'bbp_register_forum_post_type', 'my_add_bbp_to_search' ); add_filter( 'bbp_register_topic_post_type', 'my_add_bbp_to_search' ); add_filter( 'bbp_register_reply_post_type', 'my_add_bbp_to_search' );
The filters had a wrong reference to the function.
There's still three things "wrong":
- It shows the entire topic or reply in the searchresult. If you click the topic nothing is wrong, but if you click the reply, it is shown really weird with a commentform under each reply.
- Pagination doesn't work, so you're only shown 1 page of searchresults
- No blogposts are shown
But I haven't the skills to fix these issues.
#7
follow-up:
↓ 8
@
11 years ago
- Keywords has-patch added
- Priority changed from normal to high
This is because bbPress will override the native WordPress search.php template page in favor of bbPress.php. You'll need to hook the bbp_get_theme_compat_templates as well to force bbPress to return the results to your theme's search.php, which is nicely formatted to display the results in a loop (hence, why you are getting only one search result).
Here is the code (including your fix) to create a really nice unified search result page with bbPress 2.0. Search is essential to any forum and this will do the trick:
function my_add_bbp_to_search( $post_type ) { $post_type['exclude_from_search'] = false; return $post_type; } add_filter( 'bbp_register_forum_post_type', 'my_add_bbp_to_search' ); add_filter( 'bbp_register_topic_post_type', 'my_add_bbp_to_search' ); add_filter( 'bbp_register_reply_post_type', 'my_add_bbp_to_search' ); function my_bbp_get_theme_compat_templates($templates){ if ( isset($_GET['s']) ) { array_unshift($templates, 'search.php'); } return $templates; } add_filter( 'bbp_get_theme_compat_templates', 'my_bbp_get_theme_compat_templates');
#8
in reply to:
↑ 7
@
11 years ago
Created a new plugin to address this. It will also massage the search results with the proper bbPress permalinks. Was hoping for it to work in BP 1.5 too, but just realized that it's not using 2.0 when forums are setup with Groups? Overall, search in BP looks like it needs some work. Will look into it if I can make next months rent (ha ha). Here's the plugin code, may want to include it in core? Will upload it to the plugin repository, time willing...
/* Plugin Name: Search bbPress 2.0 Plugin URI: http://www.serverpress.com/products/search-bbpress Description: Adds bbPress 2.0 to WordPress search results with links back to the forum, topic, and replies. Version: 1.0 Author: Stephen Carroll Author URI: http://www.steveorevo.com License: OpenSource under GPL2 */ // Create our main bbPress Search object global $bbpsearch; $bbpsearch = new bbPressSearch(); // Define our main Content Filter class class bbPressSearch { // Hook into the WordPres Shortcode API in our constructor function __construct(){ // Add bbPress to WordPress search results add_filter( 'bbp_get_theme_compat_templates', array(&$this, 'bbp_get_theme_compat_templates') ); add_filter( 'bbp_register_forum_post_type', array(&$this, 'bbp_register_search') ); add_filter( 'bbp_register_topic_post_type', array(&$this, 'bbp_register_search') ); add_filter( 'bbp_register_reply_post_type', array(&$this, 'bbp_register_search') ); add_filter( 'the_permalink', array(&$this, 'the_permalink') ); } function the_permalink($post_link){ // Remap forum replies' permalink to proper reply url (forum topic#post) global $post; if ($post->post_type == 'reply') { $post_link = bbp_get_reply_url($post->ID); // Omit 'reply' link that maps to incorrect post template $post->comment_status = "closed"; } return $post_link; } function bbp_get_theme_compat_templates($templates){ // Tell bbPress to favor your template's native search.php when looking at results if ( isset($_GET['s']) ) { array_unshift($templates, 'search.php'); } return $templates; } function bbp_register_search($post_type){ // Include bbPress in search results $post_type['exclude_from_search'] = false; return $post_type; } }
#10
@
10 years ago
- Milestone changed from 2.1 to Future Release
Needs to be a dedicated unified search template that overloads the default. Probably needs to be punted to 2.2.
#12
@
9 years ago
- Keywords needs-patch added; has-patch removed
- Milestone changed from Future Release to 2.3
Quick update on this...
This requires a new template part to load replies, in a loop, that also includes some link to the topic they are in. What this looks like, and how it works, could be anything. We'd likely also want to use this template for the User > Replies Created page, since right now there's no context to what those replies are actually replying to.
#17
@
9 years ago
Todo on second pass:
- Search form
- Search form widget
- Double-check pagination
- Start looking at BuddyPress integration
- Better templates/template file structure
- Default search page if no results/no search
#18
@
9 years ago
- Keywords has-patch added; needs-patch removed
In 1575.2.diff, I think I'm on the right track with the permastruct rewrites. They are based on the WordPress search. I've also added a search form widget and rudimentary search result templates to facilitate testing.
#19
@
9 years ago
Patch is looking like a great first pass.
- Uses get_the_ID() in the templates so they put out correct results. Is it worth modifying bbp_get_reply_id(), bbp_get_topic_id(), and bbp_get_forum_id() to use get_the_ID() correctly if in a search query?
- Will need pagination, which is moderately annoying because the rules are more complex. (Use the topic views as an example if you need to.)
- The templates need iterating to look more like forum post results. Thinking something similar to loop-single-reply.php, but separated out.
- /forums/search/ should resolve correctly, even if there's no query string. That way there's a page with a form all the time, even if the widget is not used.
- I think the loop stuff should be extracted into its own file. Do you think we'll need several files similar to the other components? Do you see search needing capabilities, functions, template tags, etc? (/includes/search/*.*)
- It runs quite a few queries for each result; wonder what we'll be able to do to optimize it later.
New patch uses get_the_ID() to make the testing templates work as intended.
#20
@
9 years ago
Shoot. Didn't notice the .diff extention. Above patch is a 3rd iteration, based on the 2nd.
#21
@
9 years ago
I think on the next pass I'm going to break search into a separate directory in /includes. It has ceased being common, and is now more similar in scope to replies, topics, users, etc.
#23
@
9 years ago
Working through templates now, should have more complete versions up this afternoon.
/topics/view does not resolve, so I'm going to have to figure out how to get a default empty search template for forums/search working properly. Right now it gives me the main blog, so I'm going to have to dig into what it thinks it is, versus what I want it to be.
#24
@
9 years ago
- Keywords needs-testing added
- Summary changed from About Search Field in BBPress 2.0 Beta 3 to Introduce dedicated forum search page with associated template logic
#25
@
9 years ago
Templates are more in line with bbPress standards, although they're going to need a second pass just to double-check style names and CSS sanity. Search has pagination and notification of no results.
To do:
- I think that for results from private forums, search results should substitute a privacy notice for the content, but leave the title intact. Thoughts?
- Still wrestling with the 404 from /forums/search.
Search hasn't been fleshed out at this point. For now, you can enable it, but it will still search regular WP posts/pages. Put something like this in your theme's functions.php