Make WordPress Core

Changeset 739


Ignore:
Timestamp:
01/08/2004 03:36:45 PM (22 years ago)
Author:
emc3
Message:

Fixed multi-word bug in search. Added conditional for no matches.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-blog-header.php

    r736 r739  
    129129    if (!$sentence) {
    130130        $s_array = explode(' ',$s);
    131         $search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$s_array[0].'\'))';
     131        $search .= '((post_title LIKE \''.$n.$s_array[0].$n.'\') OR (post_content LIKE \''.$n.$s_array[0].$n.'\'))';
    132132        for ( $i = 1; $i < count($s_array); $i = $i + 1) {
    133133            $search .= ' AND ((post_title LIKE \''.$n.$s_array[$i].$n.'\') OR (post_content LIKE \''.$n.$s_array[$i].$n.'\'))';
     
    321321$posts = $wpdb->get_results($request);
    322322
    323 
    324 // Get the categories for all the posts
    325 foreach ($posts as $post) {
    326     $post_id_list[] = $post->ID;
    327 }
    328 $post_id_list = implode(',', $post_id_list);
    329 
    330 $dogs = $wpdb->get_results("SELECT DISTINCT
    331     ID, category_id, cat_name, category_nicename, category_description
    332     FROM $tablecategories, $tablepost2cat, $tableposts
    333     WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
    334    
    335 foreach ($dogs as $catt) {
    336     $category_cache[$catt->ID][] = $catt;
    337 }
    338 
    339 // Do the same for comment numbers
    340 
    341 
    342 if (1 == count($posts)) {
    343     if ($p || $name) {
    344         $more = 1;
    345         $c = 1;
    346         $single = 1;
    347     }
    348     if ($s) { // If they were doing a search and got one result
    349         header('Location: ' . get_permalink($posts[0]->ID));
    350     }
     323// No point in doing all this work if we didn't match any posts.
     324if ($posts) {
     325    // Get the categories for all the posts
     326    foreach ($posts as $post) {
     327        $post_id_list[] = $post->ID;
     328    }
     329    $post_id_list = implode(',', $post_id_list);
     330
     331    $dogs = $wpdb->get_results("SELECT DISTINCT
     332        ID, category_id, cat_name, category_nicename, category_description
     333        FROM $tablecategories, $tablepost2cat, $tableposts
     334        WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");
     335       
     336    foreach ($dogs as $catt) {
     337        $category_cache[$catt->ID][] = $catt;
     338    }
     339
     340    // Do the same for comment numbers
     341
     342
     343    if (1 == count($posts)) {
     344        if ($p || $name) {
     345            $more = 1;
     346            $c = 1;
     347            $single = 1;
     348        }
     349        if ($s) { // If they were doing a search and got one result
     350            header('Location: ' . get_permalink($posts[0]->ID));
     351        }
     352}
    351353}
    352354?>
Note: See TracChangeset for help on using the changeset viewer.