Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Rewrite Post type URL to be it's ID instead of the slug. */
- function custom_link($post_link, $post = 0) {
- if($post->post_type === 'task') { //My post type is "task". Change it to what is required.
- return home_url('task/' . $post->ID . '/'); //change "task" to your post type
- }
- else{
- return $post_link;
- }
- }
- add_filter('post_type_link', 'custom_link', 1, 3);
- function custom_rewrite(){
- add_rewrite_rule('task/([0-9]+)?$', 'index.php?post_type=task&p=$matches[1]', 'top'); // change task to your post type.
- }
- add_action('init', 'custom_rewrite');
Add Comment
Please, Sign In to add comment