custom post type with post_id in permalink structure
-
I am creating a custom content type by ‘coding’. I don’t like the CMS Press plugin because it limits me from editing these ‘dynamic’ post types. I want to add new features and not just pick a couple of ‘standard’ features.
What i liked about the CMS Press plugin was the way it created the permalinks. Just like it should.
https://www.example.com/post-type/post-id/post-name/
I have been searching the web for 48 hours but without result.
add_filter('post_type_link', 'webspot_type_link', 1, 3); function webspot_type_link($post_link, $id = 0, $leavename = false) { if (strpos('%webspot_id%', $post_link) < 0) { return $post_link; } $post = get_post($id); if (!is_object($post) || $post->post_type != 'webspot') { return $post_link; } return str_replace('%webspot_id%', $post->ID, $post_link); }
Gives me the right link for the content type ‘webspot’.
But, i know i miss a step. But whát is that step? It is not been explained anywhere? How do i let this url make it work.
I do not want wordpress to ‘search’ on the post-name, but just on the post-ID. In the pretty url i want the post-slug-name as wel, but it should be meaningless so i can edit it at all times, because the post is being retrieved by getting the post-id.
How to accomplish this. when i only add this wordpress_type_link, it results in correct urls, but when i click on the posts, i get a 404 error.
What do i have to do to make this work? The final url should be:
https://www.example.com/webspot/39/this-is-a-webspot-post/
- The topic ‘custom post type with post_id in permalink structure’ is closed to new replies.