自从作者停止工作以来,我一直在维护WordPress的SearchEverything插件。我今天将我的一个网站升级到wp 3.7,但在搜索时出现以下错误:
WordPress database error: [您的SQL语法有错误;请查看与您的MySQL server版本对应的手册,以了解可在附近使用的正确语法\'))) AND ncca_wp_posts.post_type IN (\'post\', \'page\',
\'attachment\', \'archive\', \'r\'
第1行]
SELECT DISTINCT SQL_CALC_FOUND_ROWS
ncca_wp_posts.*
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
编辑:谢谢凯撒。下次上船。如上所述,我可以看到错误是由SQL语法错误引起的,但我不知道如何修复它。有人能建议如何修改这行代码以使其正常工作吗?
SO网友:RoseCoder
多亏了@Pat J,我删除了引起我问题的语法。对于感兴趣的用户,在Search Everything插件的第198-221行中有以下功能:
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
//COMMENT OUT/REMOVE
//$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 \';
}
//COMMENT OUT/REMOVE
//$search .= \')\';
return $search;
}
如果您使用的是WP 3.7上的Search Everything插件,则需要相应地编辑此函数,如果您知道得更好,则需要以不同的方式编辑此函数。(我只是个初学者)。非常感谢!!