[wp-hackers] RFC: On solving WordPress automatically adding -2, -3 to the permalink

Charles Frees-Melvin charles.freesmelvin at me.com
Sun Apr 29 10:08:01 UTC 2012


Just looking quickly at this perhaps 'foo' should be a taxonomy of products rather than a post_name (slug).

On Apr 29, 2012, at 7:00 AM, Ryan Chan wrote:

> WordPress does not allow post_name to have the same value, even we
> have used the explicit ID as the permalink format -
> /products/{post_name}/{post_ID}
> 
> e.g.
> 
> What we want:
> http://www.example.com/products/foo/1
> http://www.example.com/products/foo/2
> 
> What we get currently:
> http://www.example.com/products/foo/1
> http://www.example.com/products/foo-2/2
> 
> 
> To solve this, we have write a plugin:
> ================================
> 
> 
>        add_filter('post_type_link', function($link, $post = 0) {
> 
>            if ($post->post_type == 'product')
>            {
>                $postName = sanitize_title($post->post_title, $post->post_name);
> 
>                return home_url(sprintf('products/%s/%d', $postName,
> $post->ID));
>            }
>            else
>            {
>                return $link;
>            }
>        }, 1, 3)
> ;
> ================================
> 
> 
> Seems to be working, any comment and drawback I havn't think of?
> 
> Thanks.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers



More information about the wp-hackers mailing list