Make WordPress Core

Ticket #20044: 20044.2.diff

File 20044.2.diff, 1.6 KB (added by wonderboymusic, 12 years ago)
  • src/wp-includes/query.php

     
    19651965                        if ( $n )
    19661966                                $q['search_orderby_title'][] = "$wpdb->posts.post_title LIKE '%$term%'";
    19671967
    1968                         $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))";
     1968                        $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_name LIKE '{$n}{$term}{$n}'))";
    19691969                        $searchand = ' AND ';
    19701970                }
    19711971
  • tests/phpunit/tests/query/search.php

     
     1<?php
     2/**
     3 * Search functionality
     4 *
     5 * @group query
     6 * @group search
     7 */
     8class Tests_Query_Search extends WP_UnitTestCase {
     9
     10        function test_search_by_fields() {
     11                $post_id = $this->factory->post->create( array( 'post_title' => 'Taco', 'post_name' => 'burrito', 'post_content' => 'Enchilada' ) );
     12
     13                // post slug
     14                $q1 = new WP_Query( array( 's' => 'Burrito', 'fields' => 'ids' ) );
     15                $this->assertEquals( array( $post_id ), $q1->posts );
     16
     17                // post title
     18                $q2 = new WP_Query( array( 's' => 'taco', 'fields' => 'ids' ) );
     19                $this->assertEquals( array( $post_id ), $q2->posts );
     20               
     21                // post content
     22                $q3 = new WP_Query( array( 's' => 'enchilada', 'fields' => 'ids' ) );
     23                $this->assertEquals( array( $post_id ), $q3->posts );
     24        }
     25}
     26 No newline at end of file