简体   繁体   English

永久链接更改wordpress中的每个帖子更新

[英]Permalink change each post update in wordpress

I want to have a custom permalink for each new post in WordPress like: http://mysite.com/x5Kvy6 . 我想为WordPress中的每个新帖子提供一个自定义的永久链接,例如: http : //mysite.com/x5Kvy6

function wp_unique_post_slug($col,$table='wp_posts'){
     global $wpdb;

     $alphabet = array_merge( range(0, 9), range('a','z') );

     $already_exists = true;
     do {

         $guidchr = array();
         for ($i=0; $i<32; $i++)
         $guidchr[] = $alphabet[array_rand( $alphabet )];


         $guid = sprintf( "%s", implode("", array_slice($guidchr, 0, 12, true)) );

       // check that GUID is unique
       $already_exists = (boolean) $wpdb->get_var("
       SELECT COUNT($col) as the_amount FROM $table WHERE $col = '$guid'
       ");

      } while (true == $already_exists);

     return $guid;
}

This script works well when i replace the fontion in post.php (wordpress core) but unfortunately the permalink change at each post uptade. 当我替换post.php(wordpress核心)中的字体时,此脚本效果很好,但不幸的是,每次更新后,永久链接都会更改。 How to avoid this? 如何避免这种情况? And how to edit a custom optional keyword (http://mysite.com/keyword). 以及如何编辑自定义可选关键字(http://mysite.com/keyword)。

Any idea is welcome! 任何想法都欢迎!

Read this 读这个

http://codex.wordpress.org/Using_Permalinks http://codex.wordpress.org/Using_Permalinks

在此处输入图片说明

Or 要么

function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) {

if($slug!=""){
  $random=rand(11111,99999); //I needed 5 digit random
  $slug = $random;
}
return $slug;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM