1
votes

I'm using a custom theme on Wordpress 4.1.1, and receive the following error every 2-3 hours. While I see there is a SQL syntax error, I don't understand what is causing it.

I am using PHP version 5.4.38 and MySQL Version 5.5.42-cll.

[15-Apr-2015 17:45:54 UTC] 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 'GROUP BY wp_posts.ID ORDER BY distance desc LIMIT 0, 12' at line 6 for query SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_posts.ID, 3956 * 2 * ASIN(SQRT( POWER(SIN((t1.meta_value - 0 ) * pi()/180 / 2), 2) +COS(t1.meta_value * pi()/180) * COS(0 * pi()/180) * POWER(SIN((t2.meta_value - 0) * pi()/180 / 2), 2) )) as distance, wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) INNER JOIN wp_postmeta AS mt1 ON ( wp_posts.ID = mt1.post_id )INNER JOIN wp_postmeta AS wlt1 ON ( wp_posts.ID = wlt1.post_id ) INNER JOIN wp_postmeta AS wlt2 ON ( wp_posts.ID = wlt2.post_id ) INNER JOIN wp_postmeta AS t1 ON (wp_posts.ID = t1.post_id) INNER JOIN wp_postmeta AS t2 ON (wp_posts.ID = t2.post_id) WHERE 1=1 AND (((wp_posts.post_title LIKE '%%') OR (wp_posts.post_content LIKE '% %'))) AND (wp_posts.post_password = '') AND wp_posts.post_type = 'listing_type' AND (wp_posts.post_status = 'publish') AND (wp_postmeta.meta_key = 'featured' AND ( mt1.meta_key = 'listing_expiry_date' AND CAST(mt1.meta_value AS CHAR) > '2015-04-15 20:45:54' )) AND t1.meta_key = 'map-lat' AND t1.meta_value != '' AND t2.meta_key = 'map-log' AND t2.meta_value != ''AND ( ( wlt1.meta_key = 'map-lat' AND wlt1.meta_value BETWEEN 33.4535 AND 34.8991 ) AND ( wlt2.meta_key = 'map-log' AND wlt2.meta_value BETWEEN -85.0698 AND -83.5123 ) OR ( wlt2.meta_key = 'map-zip' AND wlt2.meta_value = '30004' ) ) GROUP BY wlt2.post_id GROUP BY wp_posts.ID ORDER BY distance desc LIMIT 0, 12 made by require('wp-blog-header.php'), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts

2
Cleaned up a little sentence structure and fixed formatting.Nathaniel Ford

2 Answers

2
votes

The problem is most likely in one of your wordpress crons. That is why you are only seeing it every 2 hours. Although you don't need a tool to see what crons run I would recommend installing the Crontrol plugin which allows you to easily see and control when crons run. From there you can dig into your plugins and find out where it's coming from.

Otherwise the issue is coming from the dual GROUP BY clauses.

0
votes

The GROUP BY statement is happening twice: ... GROUP BY wlt2.post_id GROUP BY wp_posts.ID ...

I'm not sure which statement you actually want here, but that is the cause of the error.