Ticket #32824: 32824.post-slug-and-term-description-not-considered-for-search.patch
| File 32824.post-slug-and-term-description-not-considered-for-search.patch, 3.4 KB (added by , 7 months ago) |
|---|
-
src/wp-includes/class-wp-query.php
1452 1452 $searchand = ''; 1453 1453 $query_vars['search_orderby_title'] = array(); 1454 1454 1455 $default_search_columns = array( 'post_title', 'post_excerpt', 'post_content' );1455 $default_search_columns = array( 'post_title', 'post_excerpt', 'post_content', 'post_name' ); 1456 1456 $search_columns = ! empty( $query_vars['search_columns'] ) ? $query_vars['search_columns'] : $default_search_columns; 1457 1457 if ( ! is_array( $search_columns ) ) { 1458 1458 $search_columns = array( $search_columns ); -
src/wp-includes/class-wp-term-query.php
1107 1107 1108 1108 $like = '%' . $wpdb->esc_like( $search ) . '%'; 1109 1109 1110 return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s)) ', $like, $like );1110 return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s)) OR (tt.description LIKE %s)', $like, $like, $like ); 1111 1111 } 1112 1112 1113 1113 /** -
tests/phpunit/tests/query/search.php
644 644 public function filter_posts_search( $sql ) { 645 645 return $sql . ' /* posts_search */'; 646 646 } 647 648 /** 649 * Ticket #32824 650 * 651 * Test to check when search term mactched with the post_name 652 * then it returns data 653 * 654 * @return void 655 */ 656 public function test_search_matches_post_slug() { 657 // Create a post where ONLY the slug contains the search keyword. 658 $post_id = self::factory()->post->create( 659 array( 660 'post_title' => 'Completely unrelated title', 661 'post_content' => 'Nothing to see here', 662 'post_name' => 'my-special-search-slug', 663 ) 664 ); 665 666 // Run a search query using a keyword from the slug. 667 $query = new WP_Query( 668 array( 669 's' => 'special-search', 670 'posts_per_page' => -1, 671 ) 672 ); 673 674 // Assert that the post is returned. 675 $this->assertContains( 676 $post_id, 677 wp_list_pluck( $query->posts, 'ID' ), 678 'Search query should return posts when the search term matches the post slug.' 679 ); 680 } 681 647 682 } -
tests/phpunit/tests/term/query.php
1207 1207 1208 1208 $this->assertSame( ltrim( $q->request ), $q->request, 'The query has leading whitespace' ); 1209 1209 } 1210 1211 /** 1212 * Ticket #32824 1213 * 1214 * Test to check when search term mactched with the description column 1215 * of wp_term_taxonomy table, it returns data 1216 * 1217 * @return void 1218 */ 1219 public function test_search_matches_term_description() { 1220 1221 $term = wp_insert_term( 1222 'Some category', 1223 'category', 1224 array( 1225 'slug' => 'some-category', 1226 'description' => 'Unique', 1227 ) 1228 ); 1229 1230 $query = new WP_Term_Query( 1231 array( 1232 'taxonomy' => 'test_tax', 1233 'search' => 'unique', 1234 'hide_empty' => false, 1235 ) 1236 ); 1237 1238 $terms = $query->get_terms(); 1239 $this->assertContains( 1240 $term['term_id'], 1241 wp_list_pluck( $terms, 'term_id' ) 1242 ); 1243 } 1244 1210 1245 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)