#1671 closed enhancement (fixed)
Restrict searches by site section
Reported by: | keesiemeijer | Owned by: | coffee2code |
---|---|---|---|
Milestone: | Priority: | normal | |
Component: | Developer Hub | Keywords: | has-patch |
Cc: |
Description
Search results from a search with no filters have both handbook and code reference posts in them.
See https://developer.wordpress.org/?s=404
Let's use site section specific post types when searching without filters.
Attachments (6)
Change History (28)
#1
@
8 years ago
- Keywords has-patch added
Patch 1671.1 adds specific site section search when no filters are used. It correctly doesn't check all filters on results pages if no filters were used. All search query customizations are moved to the DevHub_Search
class.
It also adds the ability to search the handbooks with urls like https://developer.wordpress.org/plugins/?s=search-term
When searching a handbook the filters are removed from the searchform
#2
@
8 years ago
- Owner set to coffee2code
- Status changed from new to accepted
@keesiemeijer: Excellent! I've been meaning to both extract the search-related functionality into its own include file and to separate searches between the code reference and handbooks.
I'm going to look at the search separation handling a bit more and see if some of it is more appropriate for the Handbook plugin. It could be beneficial for the make sites, since searching from the p2 seems like it should only return posts and pages whereas searching from the handbooks should only return handbook pages, much as we want here.
#3
@
8 years ago
Good point. I agree it should come with the plugin.
The difficulty, I think, will be to determine If you're on a handbook page or not. I've used a match to the $_SERVER['REQUEST_URI']
for this. I think it's the only sane way because the post_type
query var can be changed at any time (even on the front end). Right now it's a regex match with the post type names, but you could use the post type rewrite array to determine the correct match. Or maybe there is an even better way I don't know about :)
#4
@
8 years ago
I don't think the handbook plugin should interfere with queries more than it already does. Queries should be theme territory as they all have different needs.
I've created a ticket #1693 to make it easier for themes to do (search) queries themselves.
As an example for this theme, using the functions for search queries we could do something like this
function pre_get_posts( $query ) {
if ( !( !is_admin() && $query->is_main_query() && $query->is_search() ) ) {
return;
}
if( wporg_is_handbook() ) {
// Search only in current handbook post type.
// just to make sure. post type should already be set
$query->set( 'post_type', wporg_get_current_handbook() );
} else {
// Search parsed post types instead of all post types.
$query->set( 'post_type', DevHub\get_parsed_post_types() );
}
}
#15
@
8 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
@coffee2code: As long as we're defining functions in the handbook plugin and using them in the DevHub theme, I think we should do function_exists()
checks inside of wporg-developer.
My local DevHub environment is currently tossing a fatal because I'm not loading the handbook plugin, for instance.
See 1671.2.patch
#16
@
8 years ago
Discovered another fatal in user-content.php, addressed in 1671.3.patch.
#17
@
8 years ago
1671.4.patch address more. I kind of wonder if maybe we shouldn't shim these functions in wporg-developer if we're going to be using them everywhere. It would be a lot cleaner than doing function_exists()
calls in the various contexts.
#18
@
8 years ago
1671.5.patch Adds the handbook data from the handbook functions to the current query. This way you don't have to check if the functions exists every time you need handbook data from the current query.
Search with section specific post types