Guest User

Untitled

a guest
Nov 21st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. <?php
  2. /* Rewrite Post type URL to be it's ID instead of the slug. */
  3.  
  4. function custom_link($post_link, $post = 0) {
  5. if($post->post_type === 'task') { //My post type is "task". Change it to what is required.
  6. return home_url('task/' . $post->ID . '/'); //change "task" to your post type
  7. }
  8. else{
  9. return $post_link;
  10. }
  11. }
  12. add_filter('post_type_link', 'custom_link', 1, 3);
  13.  
  14. function custom_rewrite(){
  15. add_rewrite_rule('task/([0-9]+)?$', 'index.php?post_type=task&p=$matches[1]', 'top'); // change task to your post type.
  16. }
  17. add_action('init', 'custom_rewrite');
Add Comment
Please, Sign In to add comment