Permalink change each post update in wordpress

帅比萌擦擦* 提交于 2019-12-08 06:44:39

问题


I want to have a custom permalink for each new post in WordPress like: 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. How to avoid this? And how to edit a custom optional keyword (http://mysite.com/keyword).

Any idea is welcome!


回答1:


Read this

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;

}



回答2:


You would like to try this plugin.

http://wordpress.org/extend/plugins/custom-permalinks/



来源:https://stackoverflow.com/questions/11763795/permalink-change-each-post-update-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!