WordPress.org

Ready to get started?Download WordPress

Forums

Custom post type permalink rewrite (10 posts)

  1. hydroplane
    Member
    Posted 4 years ago #

    I've set my custom permalink structure as http://site.com/%postname%/ but despite this the permalinks for custom post type result in http://site.com/custom-post-type/%postname%/

    How can I get rid of the custom-post-type part?

  2. Can you be more specific as to what, precisely, custom-post-type is? Like actual examples of REAL urls. If it's what I think, then that feature is as designed. But I want to be sure :)

    Also, having your permalinks be %postname% is a bad idea.

    For details, read http://ottopress.com/2010/category-in-permalinks-considered-harmful/

  3. IckataNET
    Member
    Posted 4 years ago #

    hydroplane: try to add empty string for the slug prefix when registering your post type:

    register_post_type('my_custom_post_type', array(
    	//...
    	'rewrite' => array('slug'=>'','with_front'=>false),
    	//...
    ));
  4. granulr
    Member
    Posted 4 years ago #

    I'm also looking for a solution to this problem... When you add an empty string like the above example I get a 404 page. Even after reseting permalnks.

  5. jacobdubail
    Member
    Posted 3 years ago #

    I have the same exact problem. Does anyone have a solution? I can rewrite the slug to be a single character, but that's not going to fly. If my regular posts can follow this permalink structure, why can't custom post types?

  6. richarduk
    Member
    Posted 3 years ago #

    I can confirm that (in my case) IckataNET has the right answer. Resaving permalinks works.

    .htaccess not rewritable? CMOD 666

  7. jacobdubail
    Member
    Posted 3 years ago #

    I can confirm that IckataNET's solution doesn't work for me. I still get a 404 after saving the permalinks anew.

  8. headway
    Member
    Posted 3 years ago #

    I had the same issue and found this post to be very helpful: (http://wpengineer.com/2044/custom-post-type-and-permalink/)

    Re-saving the Permalinks structure in Settings fixed everything.

  9. Zane Matthew
    Member
    Posted 3 years ago #

    I can confirm that this:

    register_post_type('my_custom_post_type', array(
    	//...
    	'rewrite' => array('slug'=>'','with_front'=>false),
    	//...
    ));

    did work for me.

  10. security_man
    Member
    Posted 3 years ago #

    I can confirm that IckataNET's solution doesn't work for me. I still get a 404 after saving the permalinks anew.

    I am pretty sure this has something to do with 3.04 as when i was using 3.0? previously it worked fine.

    The really odd thing is that one of my custom post types is working fine and the other is not.

    This is the register post type for the one that works:

    function my_custom_init()
    {
      $labels = array(
        'name' => _x('Websites', 'post type general name'),
        'singular_name' => _x('Website', 'post type singular name'),
        'add_new' => _x('Add New', 'website'),
        'add_new_item' => __('Add New Website'),
        'edit_item' => __('Edit Website'),
        'new_item' => __('New Website'),
        'view_item' => __('View Website'),
        'search_items' => __('Search Websites'),
        'not_found' =>  __('No Websites found'),
        'not_found_in_trash' => __('No Websites found in Trash'),
        'parent_item_colon' => ''
      );
      $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'taxonomies' => array( 'types','features'),
        'menu_position'=>5,
        'supports' => array('title','editor')
      );
      register_post_type('website',$args);
    }

    and this is the one that doesnt work

    function create_qa_post_types() {
    	 $labels = array(
    		'name' => _x( 'FAQ Categories', 'taxonomy general name' ),
    		'singular_name' => _x( 'FAQ Category', 'taxonomy singular name' ),
    		'search_items' =>  __( 'Search FAQ Categories' ),
    		'all_items' => __( 'All FAQ Categories' ),
    		'parent_item' => __( 'Parent FAQ Category' ),
    		'parent_item_colon' => __( 'Parent FAQ Category:' ),
    		'edit_item' => __( 'Edit FAQ Category' ),
    		'update_item' => __( 'Update FAQ Category' ),
    		'add_new_item' => __( 'Add New FAQ Category' ),
    		'new_item_name' => __( 'New FAQ Category Name' ),
      );
      	register_taxonomy('faq_category',array('qa_faqs'), array(
    		'hierarchical' => true,
    		'labels' => $labels,
    		'show_ui' => true,
    		'query_var' => true,
    		'rewrite' => array( 'slug' => 'faq-category' ),
      ));
    	register_post_type( 'qa_faqs',
    		array(
    			'labels' => array(
    				'name' => __( 'FAQs' ),
    				'singular_name' => __( 'FAQ' ),
    				'edit_item'	=>	__( 'Edit FAQ'),
    				'add_new_item'	=>	__( 'Add FAQ')
    			),
    			'public' => true,
    			'show_ui' => true,
    			'capability_type' => 'post',
    	//...
    	'rewrite' => true,
    	//...
    			'taxonomies' => array( 'FAQs '),
    			'supports' => array('title','editor')
    		)
    	);
    }

    Even if i make them identical one will work and the other does not. this is truly odd and frustrating.

Topic Closed

This topic has been closed to new replies.

About this Topic