I have been personally maintaining the Search Everything plugin for WordPress since the authors stopped. I upgraded one of my sites to wp 3.7 today but i get this error when i search:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))) AND ncca_wp_posts.post_type IN ('post', 'page', 'attachment', 'archive', 'r' at line 1]

FROM ncca_wp_posts 
LEFT JOIN ncca_wp_term_relationships AS trel 
    ON ( ncca_wp_posts.ID = trel.object_id ) 
LEFT JOIN ncca_wp_term_taxonomy AS ttax 
    ON ( 
        ( ttax.taxonomy = 'category' 
            OR ttax.taxonomy = 'post_tag' 
            OR ttax.taxonomy = 'years' 
            OR ttax.taxonomy = 'archive-tags' 
            OR ttax.taxonomy = 'course'
        AND trel.term_taxonomy_id = ttax.term_taxonomy_id
LEFT JOIN ncca_wp_terms AS tter 
    ON (ttax.term_id = tter.term_id) 
LEFT JOIN ncca_wp_postmeta AS m 
    ON (ncca_wp_posts.ID = m.post_id) 
WHERE 1=1 
    AND ( 
            AND ncca_wp_posts.post_type IN ('post', 'page', 'attachment', 'archive', 'research-project') 
            AND (
                ncca_wp_posts.post_status = 'publish' 
                OR ncca_wp_posts.post_status = 'private'
        AND post_type != 'revision'
    AND post_status != 'future' 
    ORDER BY ncca_wp_posts.post_title LIKE '% %' DESC, ncca_wp_posts.post_date DESC LIMIT 0, 24

Edit: Thank you kaiser. Taken on board for next time. I can see the error is being caused by an SQL syntax error, as stated above, but I cannot figure out how to fix it. Can anybody suggest how to alter this line of code to make it work correctly?

  • For future questions: Please format your question always as good as possible. Not only because it serves a purpose as reference for later readers as well, but also because you'll notice simple mistakes, typos and other road blocking, site breaking bugs by yourself. See the reformatted question and tell us what you think the problem might be - of course in an edit (not in a comment). Hint: The error message already tells a lot about what might be the problem.
    – kaiser
    Commented Oct 26, 2013 at 19:58
  • 2
    It looks like you have two ANDs in a row at the start of your WHERE clause. Why do you have the empty parentheses at the start? (ie, the ((())) bit?)
    – Pat J
    Commented Oct 26, 2013 at 21:02
  • Sorted! I will post the relevant function to edit as an answer
    – RoseCoder
    Commented Oct 26, 2013 at 21:28

1 Answer 1


Thanks to @Pat J i removed the syntax that was causing me problems. For those who are interested, inside the Search Everything plugin, on line 198 - 221 there is the following function:

    function se_search_default() {

    global $wpdb;

    $n = ( isset( $this->query_instance->query_vars['exact'] ) && $this->query_instance->query_vars['exact'] ) ? '' : '%';
    $search = '';
    $seperator = '';
    $terms = $this->se_get_search_terms();

    // if it's not a sentance add other terms

    //$search .= '(';
    foreach ( $terms as $term ) {
        $search .= $seperator;

        $search .= sprintf( "((%s.post_title LIKE '%s%s%s') OR (%s.post_content LIKE '%s%s%s'))", $wpdb->posts, $n, $term, $n, $wpdb->posts, $n, $term, $n );

        $seperator = ' AND ';
    //$search .= ')';
    return $search;

If you are using the Search Everything plugin on WP 3.7, you will need to edit this function accordingly, or differently if you know better. ( I am merely a beginner ). Many thanks!!

Not the answer you're looking for? Browse other questions tagged or ask your own question.