Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

4 Answers 4

Change this:

'rewrite' => array('slug' => 'nos-soins-et-services');

To this:

'rewrite' => array('slug' => 'nos-soins-et-services', 'with_front' => true);

share|improve this answer
    
I tried already front with true, but it did'nt worked. See my edited questions, I got it ! Everything rocks now... –  Studiomambo Apr 28 '11 at 17:07
    
This would work but you may have written your code wrong. –  xLRDxREVENGEx May 28 '11 at 18:43

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.

share|improve this answer
    
Nope ! I used this one : /%postname%. My rewrite -> slug didn't worked for my custom post type, so I turned it off with false. I know there's a solution like : add_action( 'init', 'ss_permalinks' ); function ss_permalinks() { add_rewrite_rule( '([^/]+)/all/?', 'index.php?view=all&service=$matches[1]', 'top' ); } add_filter( 'query_vars', 'ss_query_vars' ); function ss_query_vars( $query_vars ) { $query_vars[] = 'view'; return $query_vars; } But I'm a newbie with regex, I don't get the regex code with the add_rewrite_rule() function... –  Studiomambo Apr 27 '11 at 23:49
    
if flushing the rules doesn't work as Scribu said, there must be an error elsewhere, you certainly should not have to add a rewrite rule manually. post all of your cpt code here so we can have a look. –  Milo Apr 27 '11 at 23:59
    
code register_post_type('cpt_soins', array( 'label' => 'cpt_soins','description' => 'offres/produits menu Soins & services','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false, code –  Studiomambo Apr 28 '11 at 0:10
    
code'rewrite' => array('slug' => 'nos-soins-et-services'),'query_var' => true,'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisi‌​ons','thumbnail','author','page-attributes',),'taxonomies' => array('category','post_tag',),code –  Studiomambo Apr 28 '11 at 0:11
    
code'labels' => array ('name' => 'cpt_soins','singular_name' => 'cpt_soins','menu_name' => 'Soins & services','add_new' => 'Nouvel article','search_items' => 'Search Soins & services','not_found' => 'Aucun article trouvé','not_found_in_trash' => 'Aucun article dans la poubelle','parent' => 'Parent Soins & services', ),) );code –  Studiomambo Apr 28 '11 at 0:13

You need to flush the rewrite rules after changing the 'rewrite' arg. This can be done most easily by accessing WP Admin -> Settings -> Permalinks.

share|improve this answer
    
I have already force the flush, but without success (manually and within the code...) –  Studiomambo Apr 27 '11 at 23:54
    
I've recently heard about a super-flush: Switch to default permalinks, save, then switch back to your chosen permalink structure. Don't know if it helps. –  scribu Apr 28 '11 at 0:00
    
Also, it would be useful if you posted the entire post type definition (without the labels, though). –  scribu Apr 28 '11 at 0:02
    
I already tried this. Without success... –  Studiomambo Apr 28 '11 at 0:14

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 ! :-)

share|improve this answer
    
Your better off just creating them using the code from the codex. Most of the custom post type plugins are bloated and contain more than you need. –  Chris_O Apr 28 '11 at 17:44
    
You could always use this themergency.com/generators/wordpress-custom-post-types –  xLRDxREVENGEx May 28 '11 at 18:43
    
@xLRDxREVENGEx That is very cool. –  Chris_O May 28 '11 at 19:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.