• As a novice php hacker, I’m pretty impressed that I managed to get the search feature to search both posts and comments at once. But since this wasn’t the standard, it’s possible there is a good reason for not doing this. So can anyone tell me if this is ok? The functionality I changed is all in index.php as follows (mostly cribbed from edit-comments.php):

    Replace:

    <?php endforeach; else: ?>
    '<?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>
    </div>'

    with


    '<?php endforeach; endif; ?>
    <?php if (isset($_GET['s'])) : ?>
    <?php $s = $wpdb->escape($_GET['s']);
    $comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE
    comment_author LIKE '%$s%' OR
    comment_author_url LIKE ('%$s%') OR
    comment_content LIKE ('%$s%')
    ORDER BY comment_date DESC"); ?>
    <?php if ($comments) : printf(__('Search results for %s in comments:'),$s) ; foreach ($comments as $comment) : ?>
    <?php $authordata = get_userdata($wpdb->get_var("SELECT post_author FROM $tableposts WHERE ID = $comment->comment_post_ID"));
    $comment_status = wp_get_comment_status($comment->comment_ID);
    if ('unapproved' != $comment_status) : ?>
    <?php echo '

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘searching posts and comments’ is closed to new replies.