下载资源后端资源详情
文章ID连续.zip
大小:1.48KB
价格:10积分
下载量:0
评分:
5.0
上传者:huayula
更新日期:2024-07-21

WordPress原创插件:文章ID连续 无空ID免费

资源文件列表(大概)

文件名
大小
文章ID连续/双击获取更多.url
110B
文章ID连续/Continuous Post IDs.php
1.39KB
文章ID连续/
-

资源内容介绍

WordPress原创插件:文章ID连续 无空ID【免费】启用插件后,发表新文章时,文章ID将会连续不间断且没有空ID支持任何操作不会占用ID对前期未使用的空ID,自动检测并使用
<?php// 确保不会在其他操作中占用IDadd_action('admin_menu', 'continuous_post_ids_remove_hooks');function continuous_post_ids_remove_hooks() { remove_action('wp_insert_post', 'wp_update_term_count'); remove_action('wp_insert_post', 'wp_update_comment_count');}// 在发表新文章时确保ID连续且没有空IDadd_filter('wp_insert_post_data', 'continuous_post_ids_set_post_id', 10, 2);function continuous_post_ids_set_post_id($data, $postarr) { if ($data['post_status'] == 'publish' && $data['post_type'] == 'post') { global $wpdb; $unused_post_id = continuous_post_ids_get_unused_id(); if ($unused_post_id) { $data['ID'] = $unused_post_id; } } return $data;}// 查询未使用的IDfunction continuous_post_ids_get_unused_id() { global $wpdb; $sql = "SELECT a.ID + 1 AS unused_id FROM $wpdb->posts a LEFT JOIN $wpdb->posts b ON a.ID + 1 = b.ID WHERE a.post_type = 'post' AND a.post_status = 'publish' AND b.ID IS NULL ORDER BY a.ID LIMIT 1"; return $wpdb->get_var($sql);}

用户评论 (0)

发表评论

captcha