Making WordPress.org

Changeset 3241


Ignore:
Timestamp:
05/24/2016 10:38:16 PM (10 years ago)
Author:
coffee2code
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/search.php

    r3240 r3241  
    4242                $query->set( 'order', 'ASC' );
    4343
    44                 // If user has '()' at end of a search string, assume they want a specific function/method.
    45                 $s = htmlentities( $query->get( 's' ) );
    46                 if ( '()' === substr( $s, -2 ) ) {
    47                         // Enable exact search.
    48                         $query->set( 'exact',     true );
    49                         // Modify the search query to omit the parentheses.
    50                         $query->set( 's',         substr( $s, 0, -2 ) ); // remove '()'
    51                         // Restrict search to function-like content.
    52                         $query->set( 'post_type', array( 'wp-parser-function', 'wp-parser-method' ) );
     44                // Separates searches for handbook pages from non-handbook pages depending on
     45                // whether the search was performed within context of a handbook page or not.
     46                if ( wporg_is_handbook() ) {
     47                        // Search only in current handbook post type.
     48                        // Just to make sure. post type should already be set.
     49                        $query->set( 'post_type', wporg_get_current_handbook() );
     50                } else {
     51                        // If user has '()' at end of a search string, assume they want a specific function/method.
     52                        $s = htmlentities( $query->get( 's' ) );
     53                        if ( '()' === substr( $s, -2 ) ) {
     54                                // Enable exact search.
     55                                $query->set( 'exact',     true );
     56                                // Modify the search query to omit the parentheses.
     57                                $query->set( 's',         substr( $s, 0, -2 ) ); // remove '()'
     58                                // Restrict search to function-like content.
     59                                $query->set( 'post_type', array( 'wp-parser-function', 'wp-parser-method' ) );
     60                        } else {
     61                                // Search parsed post types instead of all post types.
     62                                $query->set( 'post_type', DevHub\get_parsed_post_types() );
     63                        }
    5364                }
    5465        }
Note: See TracChangeset for help on using the changeset viewer.