• I want to change the slug of a post with a custom field.

    In example, if the custom field is “keyword” my post link will become: mysite.com/keyword.

    If the custom field is empty, i want to generate a random key like mysite.com/xV5f7A.

    How can i do that without change the wordpress core?

    Any ideas are welcome! Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You need to be careful messing with post slugs. If you change those after a post is published you will generate broken links.

    So, now I’ve warned you. My conscience is clear. 🙂 Hook into wp_insert_post_data or save_post

    http://codex.wordpress.org/Plugin_API/Action_Reference/save_post#Example

    Actually, I don’t think it breaks the link anymore. I change slugs all the time, and WP is smart enough to tell the difference. Not sure when this changed, but I know it was just talked about at WordCamp in SF on Saturday. “It just works” was the comment.

    There is a function in query.php that tries to compensate and does do a pretty good. I’ve been playing with it this morning. The system tracks old slugs in wp_postmeta under meta_key ‘_wp_old_slug’. That was much needed.

    Thread Starter another day

    (@thibaultlg)

    I tried your solution since two day and i don’t success. I lost all my hair. Can you give me an example?

    What does your code look like?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change slug with custom field in wordpress’ is closed to new replies.