I know that’s a common problem with the custom-post-types, but I’m stuck there. I created a custom-post-type named ‘cpt_soins’. I have no page with similar name (singular/plural)…
I tried with
'rewrite' => array('slug' => 'nos-soins-et-services');
when I registered my custom post type in order to display a more pretty url than “/?cpt_soins=soins-visage-a-la-rose”… But I’m stuck with a 404 error.
I want this ugly permalink: “http://localhost:8888/wordpress/?cpt_soins=soins-visage-a-la-rose” —> transformed into: “http://localhost:8888/wordpress/nos-soins-et-services/soins-visage-a-la-rose”
I know i can use the “add_rewrite_rule() with regex”. But I did’nt get working. Could you give me the code please for the functions.php in order to get my permalink ?
Thanks a lot
Change this:
'rewrite' => array('slug' => 'nos-soins-et-services');
To this:
'rewrite' => array('slug' => 'nos-soins-et-services', 'with_front' => true);
You need to flush the rewrite rules after changing the ‘rewrite’ arg. This can be done most easily by accessing WP Admin -> Settings -> Permalinks.
I’ve got it ! I used the plugin “Custom Post Type UI” in order to register my custom-post-type. I was stucked with my permalinks problems so I decided to redo everything manually without plugin. So I took the code from the codex to register my custom-pot-type and my taxonomies. I create a page template for displaying my custom-post-type, create some article under my custom post-type, and so on. Now everything work like a charm (category with my taxonomies and my articles asides my custom-post-types and top of that : the pretty permalinks).
I left the ‘rewrite’ => true. Nothing to do anymore… Don’t bother with the permalinks. Just the for the fun I tried with ‘rewrite’ => array(‘slug’ => ‘my-word-for-my-permalink’), It works as well !
Don’t forget to flush the permalinks manually and within your register function for cpt (at least once) in the functions.php…
Does anybody got some similar problem with the plugin “Custom Post Type UI” ?
Which plugin do you use for create/manage your custom-post-types ?
Thanks everybody and have fun with your custom-post-types ! 🙂
Your pretty URL is not working because you have not introduced the line
'rewrite' => false,
in theargs
array while declaring the Custom Post Type.Use this code to solve your problem….Hope this works for you
It looks like you’re using the default permalink setup. You need to enable URL rewriting with mod_rewrite to get ‘pretty’ permalinks. Read the codex permlinks page for more info.