慢查询以及如何优化函数php代码

时间:2016-04-07 09:47:22

标签: php mysql wordpress

此查询是使用Wordpress在作业中搜索关键字。这段代码让我的查询变得如此缓慢,我陷入困境。我有超过4万个帖子,但每当搜索某些内容时,结果会在几秒钟内(3-5秒)显示。

欢迎任何想法。

function get_job_listings_keyword_search( $args ) {
        global $wpdb, $job_manager_keyword;

        $conditions   = array();
        $conditions[] = "{$wpdb->posts}.post_title LIKE '%" . esc_sql( $job_manager_keyword ) . "%'";
        $conditions[] = "{$wpdb->posts}.ID IN ( SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value LIKE '%" . esc_sql( $job_manager_keyword ) . "%' )";


        $args['where'] .= " AND ( " . implode( ' OR ', $conditions ) . " ) "; 

        return $args;

0 个答案:

没有答案