WordPress纯代码检测重复文章

趣课程
趣课程
管理员
755
文章
0
粉丝
信息科技评论35阅读模式

我们在更新博客时,时间久了,有时同一篇是否发布过,现在很难确定,可以将以下代码添加在functions.php文件最后一个?>之前,在仪表盘首页就可以看到重复文章的ID了。

function detect_duplicate_posts() {
       $all_posts = get_posts(array('post_type' => 'post', 'numberposts' => -1));
       $titles = array();
       $duplicates = array();

       foreach ($all_posts as $post) {
           $title = $post->post_title;
           if (in_array($title, $titles)) {
               $duplicates[] = $post->ID;
           } else {
               $titles[] = $title;
           }
       }

       if (!empty($duplicates)) {
           echo '

重复文章ID:' . implode(', ', $duplicates) . '文章源自趣课程-https://www.qukecheng.com/1066.html

'; } } add_action('admin_notices', 'detect_duplicate_posts');
文章源自趣课程-https://www.qukecheng.com/1066.html文章源自趣课程-https://www.qukecheng.com/1066.html

文章末尾固定信息

weinxin
我的微信
微信号已复制
我的微信
微信扫一扫
 
趣课程
  • 本文由 趣课程 发表于2023 年 11 月 15 日 16:11:37
  • 转载请务必保留本文链接:https://www.qukecheng.com/1066.html

发表评论