尝试创建一种自定义方式来显示wordpress网站的帖子。在从数据库中获取我需要的确切数据时遇到问题。
所以这是我的错误:
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 Imgguid' at line 24
这是我的疑问:
$sql="SELECT Posts.post_title AS Title, ImgURL.guid AS Imgguid, Posts.guid, Posts.post_content
FROM `wp_posts` AS Posts
INNER JOIN `wp_postmeta` AS Meta ON Posts.ID = Meta.post_id
INNER JOIN `wp_postmeta` AS Featured ON Posts.ID = Featured.post_id
INNER JOIN `wp_postmeta` AS StartF ON Posts.ID = StartF.post_id
INNER JOIN `wp_postmeta` AS EndF ON Posts.ID = EndF.post_id
INNER JOIN `wp_postmeta` AS ImgID ON Posts.ID = ImgID.post_id
INNER JOIN `wp_posts` AS ImgURL ON ImgID.meta_value = ImgURL.ID
WHERE
(Featured.meta_key = '_ecp_custom_22' AND Featured.meta_value = 'yes')
AND
(StartF.meta_key = '_ecp_custom_23' AND CAST(StartF.meta_value AS DATETIME) <= CURDATE())
AND
(EndF.meta_key = '_ecp_custom_27' AND CAST(EndF.meta_value AS DATETIME) >= CURDATE())
AND
(ImgURL.post_type = 'attachment')
AND
(Posts.ID IN (SELECT relationships.object_id FROM `wp_terms` AS terms
INNER JOIN `wp_term_taxonomy` AS taxonomy ON terms.term_id = taxonomy.term_id
INNER JOIN `wp_term_relationships` AS relationships ON taxonomy.term_taxonomy_id = relationships.term_taxonomy_id
WHERE terms.name = 'Sydney'))
LIMIT 300
GROUP BY Title;";
不确定为什么它不喜欢Group By位。感谢。
答案 0 :(得分:2)
LIMIT 300
这应该在查询结束时出现。
GROUP BY Title LIMIT 300
答案 1 :(得分:-2)
(function () {})();