我使用此代码来防止添加重复的帖子,但我也需要防止重复页面。有人能帮忙吗?
function clearDuplicatePosts(){
global $wpdb;
$prefix = $wpdb->prefix;
$wpdb->query("DELETE bad_rows . * FROM ".$prefix."posts AS bad_rows INNER JOIN (
SELECT ".$prefix."posts.post_title, MIN( ".$prefix."posts.ID ) AS min_id
FROM ".$prefix."posts
GROUP BY post_title
HAVING COUNT( * ) >1
) AS good_rows ON ( good_rows.post_title = bad_rows.post_title
AND good_rows.min_id <> bad_rows.ID )");
}
add_action(\'publish_post\', \'clearDuplicatePosts\');
最合适的回答,由SO网友:Bainternet 整理而成
您可以使用相同的函数,只需将其挂接到publish_page
钩子或任何自定义的柱子类型publish_{post type name}
所以只需添加:
add_action(\'publish_page\', \'clearDuplicatePosts\');