WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Permalinks 404 with custom post type. (40 posts)

  1. lehoaian
    Member
    Posted 3 years ago #

    I have tested mattifesto's solution and it worked for me.
    Great thank to mattifesto.

  2. YoArts
    Member
    Posted 3 years ago #

    //make sure new rules will be generated for custom post type
    add_action('admin_init', 'flush_rewrite_rules');

  3. ConnieLMc
    Member
    Posted 3 years ago #

    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]

  4. amuralikumar
    Member
    Posted 3 years ago #

    @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.

  5. ConnieLMc
    Member
    Posted 3 years ago #

    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?

  6. amuralikumar
    Member
    Posted 3 years ago #

    @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.

  7. electrox
    Member
    Posted 3 years ago #

    Reload (override cache) ---> Ctrl+F5

    Salu2

  8. ConnieL
    Member
    Posted 3 years ago #

    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.

  9. ldexterldesign
    Member
    Posted 3 years ago #

    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: http://wordpress.org/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,

  10. ConnieL
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic