For unique post slug use function wp_unique_post_slug
-
use this function for unique post slug
function regenerate_post_permalink($post_type = 'post') { global $wpdb; $myrows = $wpdb->get_results("SELECT id, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type='$post_type' "); $counter = 0; foreach ($myrows as $pid) : $post_title = regenerate_post_clear_diacritics($pid->post_title); $post_title = sanitize_title_with_dashes($post_title); $new_slug = wp_unique_post_slug($post_title, $pid->id, 'publish', $post_type, 0); $sql = "UPDATE $wpdb->posts SET post_name = '" . $new_slug . "' WHERE ID = $pid->id"; $wpdb->query($sql); $counter++; endforeach; return $counter; }
More information – https://denis-creative.com/peregeneracziya-permalinkov-slagov-massovoe-izmenenie-chpu-na-sajte-wordpress/
The page I need help with: [log in to see the link]
- The topic ‘For unique post slug use function wp_unique_post_slug’ is closed to new replies.