Changeset 7827
- Timestamp:
- 11/05/2018 11:06:19 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/search.php
r7319 r7827 24 24 add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ), 20 ); 25 25 add_filter( 'posts_orderby', array( __CLASS__, 'search_posts_orderby' ), 10, 2 ); 26 add_filter( 'the_posts', array( __CLASS__, 'rerun_empty_ exact_search' ), 10, 2 );26 add_filter( 'the_posts', array( __CLASS__, 'rerun_empty_search' ), 10, 2 ); 27 27 } 28 28 … … 169 169 170 170 /** 171 * Rerun an exact search with the same criteria except exactness if no posts 172 * were found. 171 * Potentially rerun a search if no posts were found. 172 * 173 * Situations: 174 * - For an exact search, try again with the same criteria but without exactness 175 * - For a search containing characters that can be converted to HTML entities, 176 * , try again after converting those characters 173 177 * 174 178 * @access public … … 178 182 * @return array 179 183 */ 180 public static function rerun_empty_exact_search( $posts, $query ) { 181 if ( is_search() && true === $query->get( 'exact' ) && ! $query->found_posts ) { 182 $query->set( 'exact', false ); 183 $posts = $query->get_posts(); 184 public static function rerun_empty_search( $posts, $query ) { 185 if ( is_search() && ! $query->found_posts ) { 186 $s = $query->get( 's' ); 187 188 // Return exact search without exactness. 189 if ( true === $query->get( 'exact' ) ) { 190 $query->set( 'exact', false ); 191 $posts = $query->get_posts(); 192 } 193 194 // Retry HTML entity convertible search term after such a conversion. 195 elseif ( $s != ( $she = htmlentities( $s ) ) ) { 196 $query->set( 's', $she ); 197 $posts = $query->get_posts(); 198 } 184 199 } 185 200
Note: See TracChangeset
for help on using the changeset viewer.