[wp-trac] [WordPress Trac] #2974: extend search feature to include comments

WordPress Trac wp-trac at lists.automattic.com
Tue Jul 25 18:41:39 GMT 2006


#2974: extend search feature to include comments
----------------------------+-----------------------------------------------
 Reporter:  prokurator      |       Owner:  anonymous          
     Type:  enhancement     |      Status:  new                
 Priority:  normal          |   Milestone:  2.0.4              
Component:  Administration  |     Version:  2.0.3              
 Severity:  normal          |    Keywords:  search post comment
----------------------------+-----------------------------------------------
 WP provides to my knowledge only search in posts contents and titles. I
 believe it is important to include in this equation also search inside
 comments.

 It can be easily achieved since there are no identical column names in
 tables _posts and _comments.

 Here is what I suggest:

 all changes referred to function 'get_posts' from wp-includes/classes.php,
 while referring to line numbers I used latest WP 2.0.3 version.


 '''First off all we need new variable:'''
 ''$from = $wpdb->posts;''

 This line should be just after  initial introductions of all variables in
 that function - lines 274-281.

 '''Secondly, that variable needs to be updated inside search condition:'''
 just after

 if (!empty($q['s'])) { add this:

 ''$from .= ', ' . $wpdb->comments;'' (this must be after line 422)

 '''Thirdly, we need to update query in order to select data from _posts
 and _comments tables:'''

 instead of line 442:

 $search .= ')';

 we need following line:

 ''$search .= ' OR (comment_content LIKE \''.$n.$q['s'].$n.'\' AND
 '.$wpdb->comments.'.comment_post_ID = '.$wpdb->posts.'.ID))';
 ''

 and instead of line 444:

 $search = ' AND ((post_title LIKE \''.$n.$q['s'].$n.'\') OR (post_content
 LIKE \''.$n.$q['s'].$n.'\'))';

 we need following line:

 ''$search = ' AND ((post_title LIKE \''.$n.$q['s'].$n.'\') OR
 (post_content LIKE \''.$n.$q['s'].$n.'\') OR (comment_content LIKE
 '.$n.$q['s'].$n.' AND '.$wpdb->comments.'.comment_post_ID =
 '.$wpdb->posts.'.ID))';
 ''

 Finally line 651 needs to be updated too.
 It must contain new variable $from:

 ''$request = " SELECT $distinct * FROM $from $join WHERE 1=1" . $where . "
 GROUP BY " . $groupby . " ORDER BY " . $orderby . " $limits";''

 As I mentioned in the beginning since there is no identical names of
 columns in tables _posts and _comments we don't really need to add into
 query string syntax such as $wpdb->posts.'.ID' or
 $wpdb->comments.'.comment_ID'

-- 
Ticket URL: <http://trac.wordpress.org/ticket/2974>
WordPress Trac <http://wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list