SO网友:Z. Zlatev
为您测试以下筛选器工作:
function wpse245094_fist_duplicate_slug( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) {
// slug had to change, we must have a duplicate
if ( $original_slug !== $slug ) {
// try to replace `-2` with `-es`
$new_slug = preg_replace( \'#-2$#\', \'-es\', $slug );
if ( $new_slug !== $slug ) {
// if a replacement occurred ensure uniqueness again.
$slug = wp_unique_post_slug( $new_slug, $post_ID, $post_status, $post_type, $post_parent );
}
}
}
add_filter( \'wp_unique_post_slug\', \'wpse245094_fist_duplicate_slug\', 10, 6 );
它只会尝试匹配
-2
在slug结束时,只有在WP检查后更改。