wpdb - Limit left join

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 syn

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
Add a comment  | 

1 Answer 1

Reset to default 0

You 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742318743a4421374.html

相关推荐

  • wpdb - Limit left join

    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 syn

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信