Changeset 951 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
- Timestamp:
- 10/29/2014 06:02:03 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php
r948 r951 74 74 add_filter( 'post_type_link', __NAMESPACE__ . '\\method_permalink', 10, 2 ); 75 75 add_filter( 'term_link', __NAMESPACE__ . '\\taxonomy_permalink', 10, 3 ); 76 add_filter( 'the_posts', __NAMESPACE__ . '\\rerun_empty_exact_search', 10, 2 ); 76 77 add_theme_support( 'automatic-feed-links' ); 77 78 add_theme_support( 'post-thumbnails' ); … … 237 238 $query->set( 'wp-parser-source-file', str_replace( array( '.php', '/' ), array( '-php', '_' ), $query->query['wp-parser-source-file'] ) ); 238 239 } 240 241 // If user has '()' at end of a search string, assume they want a specific function/method. 242 if ( $query->is_search() ) { 243 $s = htmlentities( $query->get( 's' ) ); 244 if ( '()' === substr( $s, -2 ) ) { 245 // Enable exact search 246 $query->set( 'exact', true ); 247 // Modify the search query to omit the parentheses 248 $query->set( 's', substr( $s, 0, -2 ) ); // remove '()' 249 // Restrict search to function-like content 250 $query->set( 'post_type', array( 'wp-parser-function', 'wp-parser-method' ) ); 251 } 252 } 253 } 254 255 /** 256 * Rerun an exact search with the same criteria except exactness if no posts 257 * were found. 258 * 259 * @access public 260 * 261 * @param array $posts Array of posts after the main query 262 * @param WP_Query $query WP_Query object 263 * @return array 264 */ 265 function rerun_empty_exact_search( $posts, $query ) { 266 if ( is_search() && true === $query->get( 'exact' ) && ! $query->found_posts ) { 267 $query->set( 'exact', false ); 268 $posts = $query->get_posts(); 269 } 270 return $posts; 239 271 } 240 272
Note: See TracChangeset
for help on using the changeset viewer.