WordPress — Скрипт регенерации постоянных ссылок на записи в кириллице

Скопировать содержимое в regen-permalinks.php

Далее запустить из ssh

php regen-permalinks.php

ожидайте.

<?php
require_once 'wp-load.php';
$cyr = ['а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п', 'р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я', 'А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П', 'Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я']; $lat = ['a','b','v','g','d','e','io','zh','z','i','y','k','l','m','n','o','p', 'r','s','t','u','f','h','ts','ch','sh','sht','a','i','y','e','yu','ya', 'A','B','V','G','D','E','Io','Zh','Z','I','Y','K','L','M','N','O','P', 'R','S','T','U','F','H','Ts','Ch','Sh','Sht','A','I','Y','e','Yu','Ya'];
$post_status = 'publish';
$results = $wpdb->get_results("SELECT id,post_title,post_name FROM ".$wpdb->posts." WHERE `post_type` <> 'revision' AND `post_type` <> 'acf-field-group' AND `post_type` <> 'acf-field' AND `post_status`='".$post_status."'");
$m=count($results);

var_dump($results);
die();

foreach ($results as $key => $value) {
	if(empty($value->post_title)) continue;

	if(empty(preg_match('/^[a-z0-9-]+$/im', $value->post_name))) {
		$new_post_name = urldecode(sanitize_title(str_replace(array('№','#'),'',str_replace($cyr, $lat, $value->post_title))));
		$sqlcheck = "SELECT COUNT(id) FROM ".$wpdb->posts." WHERE `id` <> '".$value->id."' AND `id` < '".$value->id."' AND `post_name` LIKE '".$new_post_name."%'";
		$uniq = (int) $wpdb->get_var($sqlcheck);
		if($uniq > 0) {
			$new_post_name = $new_post_name."-".($uniq+1);
		}
		if ( $value->post_name != $new_post_name ) {
			wp_update_post(
				array (
					'ID'        => $value->id,
					'post_name' => $new_post_name
				)
			);
			echo "[".$key."/".$m."] #".$value->id." [".$value->post_title."] => ".$new_post_name."\r\n";
		}
	}
}

КолДваТриЧетыреОтлично! (оценок еще нет, поставь?)
Loading...