admin管理员组文章数量:1332361
I am trying to delete posts of post type using left join but i get the following 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 'LIMIT 1'
Code:
global $wpdb;
$result = $wpdb->query(
$wpdb->prepare("DELETE posts,pt,pm
FROM wp_posts posts
LEFT JOIN wp_term_relationships pt ON ( pt.object_id = posts.ID AND pt.term_taxonomy_id = %d)
LEFT JOIN wp_postmeta pm ON pm.post_id = posts.ID
WHERE posts.post_type = %s
LIMIT %d
",
456,
'listing',
1
)
);
I am trying to delete posts of post type using left join but i get the following 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 'LIMIT 1'
Code:
global $wpdb;
$result = $wpdb->query(
$wpdb->prepare("DELETE posts,pt,pm
FROM wp_posts posts
LEFT JOIN wp_term_relationships pt ON ( pt.object_id = posts.ID AND pt.term_taxonomy_id = %d)
LEFT JOIN wp_postmeta pm ON pm.post_id = posts.ID
WHERE posts.post_type = %s
LIMIT %d
",
456,
'listing',
1
)
);
Share
Improve this question
asked Jun 25, 2020 at 13:41
Mohamed OmarMohamed Omar
5191 gold badge5 silver badges17 bronze badges
1 Answer
Reset to default 0You can't use LIMIT directly with a DELETE query, it's invalid syntax. I suggest you get the query working in a tool such as MySQL Workbench to ensure your syntax is correct first then you can migrate it to your WordPress code.
本文标签: wpdbLimit left join
版权声明:本文标题:wpdb - Limit left join 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742318743a2452350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论