WordPress.org

Making WordPress.org

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#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)

1671.patch (11.8 KB) - added by keesiemeijer 3 years ago.
Search with section specific post types
1671.1.patch (18.0 KB) - added by keesiemeijer 3 years ago.
Add DevHub_Search class
1671.2.patch (483 bytes) - added by DrewAPicture 3 years ago.
function_exists()
1671.3.patch (1.4 KB) - added by DrewAPicture 3 years ago.
1671.4.patch (3.3 KB) - added by DrewAPicture 3 years ago.
But wait, there's more!
1671.5.patch (6.4 KB) - added by keesiemeijer 3 years ago.
Add handbook query vars to the current query

Download all attachments as: .zip

Change History (28)

@keesiemeijer
3 years ago

Search with section specific post types

@keesiemeijer
3 years ago

Add DevHub_Search class

#1 @keesiemeijer
3 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

Last edited 3 years ago by keesiemeijer (previous) (diff)

#2 @coffee2code
3 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 @keesiemeijer
3 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 @keesiemeijer
3 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() );
                }
        }


Last edited 3 years ago by keesiemeijer (previous) (diff)

#5 @coffee2code
3 years ago

In 3234:

Handbook plugin: Add four template tags relating to handbook pages.

Specifically: wporg_get_handbook_post_types(), wporg_is_handbook(), wporg_is_handbook_post_type(), and wporg_get_current_handbook().

Props keesiemeijer.
See #515, #1671.
Fixes #1693.

#6 @coffee2code
3 years ago

In 3235:

Handbook plugin: Add template tag wporg_get_current_handbook_home_url() to get home URL for current handbook.

See #515, #1671.

#7 @coffee2code
3 years ago

In 3236:

Handbook plugin: Don't modify handbook archive query when handling search.

Allows for handbook-only searches.

See #515, #1671.

#8 @coffee2code
3 years ago

In 3240:

developer.wordpress.org: Add inc/search.php to house search-related functionality and move such functionality out of functions.php.

Props keesiemeijer.
See #1671.

#9 @coffee2code
3 years ago

In 3241:

developer.wordpress.org: Separate handbook search results from code reference search results.

Results reflect the context of the search, either the current handbook or the code reference.

Props keesiemeijer for initial patch.
See #1671.

#10 @coffee2code
3 years ago

In 3242:

developer.wordpress.org: Disable single search result redirect for handbook searches.

See #1671.

#11 @coffee2code
3 years ago

In 3243:

developer.wordpress.org: Adjust search form to handle being used for either handbook or code reference.

  • Make form context aware for submission URL.
  • Don't display parsed post type filter checkboxes in search form for handbooks.
  • Add searchform-handbook class to form when used in handbook.

Props keesiemeijer for initial patch.
See #1671.

#12 @coffee2code
3 years ago

In 3244:

developer.wordpress.org: Disable autocomplete when search form is used for handbooks.

Props keesiemeijer.
See #1671.

#13 @coffee2code
3 years ago

In 3245:

developer.wordpress.org: Add and use template for handbook archive/search listings.

See #1671.

#14 @coffee2code
3 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 3246:

developer.wordpress.org: Don't prefix excerpts for handbook pages with post type.

Fixes #1671.

@DrewAPicture
3 years ago

function_exists()

#15 @DrewAPicture
3 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

@DrewAPicture
3 years ago

#16 @DrewAPicture
3 years ago

Discovered another fatal in user-content.php, addressed in 1671.3.patch.

@DrewAPicture
3 years ago

But wait, there's more!

#17 @DrewAPicture
3 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.

@keesiemeijer
3 years ago

Add handbook query vars to the current query

#18 @keesiemeijer
3 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.

Last edited 3 years ago by keesiemeijer (previous) (diff)

#19 @keesiemeijer
3 years ago

Maybe a better option is to add the query vars to the query in the handbook plugin itself.

#20 @coffee2code
3 years ago

In 3278:

developer.wordpress.org: Unset search filter checkboxes if no filters were explicitly set.

The behavior had gotten undone during recent search-related changes.

Props keesiemeijer for initial patch.
See #1671.

#21 @coffee2code
3 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 3281:

developer.wordpress.org: Set handbook-related flags and data once via query variables rather than assuming (or always checking for) the presence of handbook plugin template tags.

Specifically sets 'is_handbook', 'current_handbook', 'current_handbook_home_url', 'current_handbook_name'.

Props keesiemeijer.
Fixes #1671.

#22 @drewapicture
3 years ago

In 3380:

developer.wordpress.org: Replace an errant usage of wporg_is_handbook() with the alternative query variable check introduced in [3281].

See #1671.

Note: See TracTickets for help on using tickets.