I want to delete some posts that have meta_key = xxx_generate_id programmatically, here is my code
$arg = array(
'numberposts' => -1, // The number of posts to retrieve, otherwise 5
'post_type' => $publish_as,
'post_status' => $post_status,
'meta_key' => 'xxx_generate_id',
);
$quesryResults = new WP_Query($arg);
$success = 0;
$failed = 0;
if ($quesryResults->have_posts()) {
while ($quesryResults->have_posts()) {
$quesryResults->the_post();
if (wp_delete_post(get_the_ID(), true)) {
$successs++;
} else {
$failed++;
}
}
}
All posts containing meta_key = xxx_generate_id successfully deleted. But besides successfully deleting the posts it also returned an error like this
WordPress database error: [Unknown column '0' in 'field list']
UPDATE `wp_rank_math_internal_meta` SET `internal_link_count` = '0', `external_link_count` = '0', `0` = '' WHERE `object_id` = 661
WordPress database error: [Unknown column '0' in 'field list']
UPDATE `wp_rank_math_internal_meta` SET `internal_link_count` = '0', `external_link_count` = '0', `0` = '' WHERE `object_id` = 660
WordPress database error: [Unknown column '0' in 'field list']
UPDATE `wp_rank_math_internal_meta` SET `internal_link_count` = '0', `external_link_count` = '0', `0` = '' WHERE `object_id` = 652
It seems like this error is from rank math plugin.
How to solve this error? or to hide it?
2
Answers
I solved this by querying not using WP_Query but using a manual query
This is the solution to the problem
Source: https://support.rankmath.com/ticket/error-on-post-delete-and-solution/