0

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
    ) 
);

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.