• Resolved onelli

    (@onelli)


    I’m currently having a permalink problem that I can’t seem to track down.
    I’m using WP 3.0 with some custom post_types that I’ve made.
    In this example, I’m using the custom post type “event”.

    This is my custom permalink structure:
    /%category%/%postname%/

    This an example of the permalink that it provides me, that 404’s:
    https://mysite.com/event/heres-a-title/

    However, if I enter the “default permalink structure” in to the url, such as:
    https://mysite.com/?event=heres-a-title

    Then it redirects me to this, which works:
    https://mysite.com/event/heres-a-title/?event=heres-a-title

    It’s weird how “/event/heres-a-title/” doesn’t work (the permalink that wordpress gives me), but “/event/heres-a-title/?event=heres-a-title” does.

    I followed some standard tutorials on how to properly create custom post types, even a tutorial that was supposed to stop these 404’s.

    Here’s my register_post_type:

    register_post_type('event', array(
    			'label' => __('Events'),
    			'singular_label' => __('Event'),
    			'public' => true,
    			'show_ui' => true,
    			'_builtin' => false,
    			'_edit_link' => 'post.php?post=%d',
    			'capability_type' => 'post',
    			'hierarchical' => false,
    			'rewrite' => array("slug" => "event"),
    			'query_var' => "event",
    			'supports' => array('title','editor')
    ));

    Any help would be greatly appreciated. Even just a workaround to have all my custom post types permalink to the working structure would be great.

    Thanks.

Viewing 9 replies - 31 through 39 (of 39 total)
  • //make sure new rules will be generated for custom post type
    add_action('admin_init', 'flush_rewrite_rules');

    Where do I find “register_post_type arguments”in order to put in this code:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    @connielmc , If you see the code , its last line is : register_post_type('usb',$args);

    That is the wordpress function we have to use to register a new post type.
    in the above line , we are registering a new post type called usb.

    But instead of calling it directly, we are adding the post register code in a function called usb_init() and then adding it in init action by this code : add_action('init', 'usb_init');

    The complete should be put in functions.php of the theme files.

    Thank you for your explanation. I tried adding that to functions.php and got an error message to line 1012 I think, so I removed it.

    I just switched to the Thesis theme. Do you know if there is an answer to the 404 error in order to customize my permalink so I can have the page name instead of the page number?

    @connielmc, I am not sure if you will understand php codes.
    I suggest you to hire a wordpress developer for the work.

    To customize permalink , you can just go to permalink under settings in your wordpress admin.

    Reload (override cache) —> Ctrl+F5

    Salu2

    Thank you so much. I will try that the next time I have this problem. It seems to be a continual problem. I did delete one plug-in that seemed to be conflicting with others.

    After hours of experimentation this worked for me…

    The key is to ensure when you first register the post type that your post type name is different from your page (if you’re using a page template).

    This rule of thumb also applies if you’re using a plugin like: https://www.ads-software.com/extend/plugins/custom-post-type-ui/ – check the code it outputs!

    My page is named ‘Products

    My post type is named ‘product‘:

    register_post_type('<strong>product</strong>', array(	'label' => 'Products','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,'rewrite' => array('slug' => ''),'query_var' => true,'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes',),'labels' => array (
      'name' => 'Products',
      'singular_name' => 'Product',
      'menu_name' => 'Products',
      'add_new' => 'Add Product',
      'add_new_item' => 'Add New Product',
      'edit' => 'Edit',
      'edit_item' => 'Edit Product',
      'new_item' => 'New Product',
      'view' => 'View Product',
      'view_item' => 'View Product',
      'search_items' => 'Search Products',
      'not_found' => 'No Products Found',
      'not_found_in_trash' => 'No Products Found in Trash',
      'parent' => 'Parent Product',
    ),) );

    You may find you have to gut your wp_posts for a clean slate, but this solution requires no additional slug rewrites.

    Best,

    Thanks you so much for experimenting for hours. I appreciate your help.

Viewing 9 replies - 31 through 39 (of 39 total)
  • The topic ‘Permalinks 404 with custom post type.’ is closed to new replies.