Forums

Custom rewrite rules go missing when using rewrite=> array(slug=>'foo') (1 post)

  1. magicroundabout
    Member
    Posted 2 months ago #

    Hi folks,

    I've got a weird problem on a number of sites that I'm trying to diagnose.

    These sites are using custom themes with built-in custom post types. The post types are registered using an action on the init hook. e.g.

    add_action( 'init', 'register_cpt_my_type' );
    function register_cpt_my_type() {
       $args = ...;
       register_post_type( 'my_type', $args );

    Some of my themes have custom post types set up using:

    has_archive => true,
    rewrite => array( 'slug' => 'my_types' ),

    Others have:

    has_archive => 'my_types',
    rewrite=>true

    The problem I have ONLY affect those sites/themes using this always thought that these would be equivalent. I've learned that this is not the case, but won't go into detail here.

    Every now and then sites using the former approach (rewrite=> array('slug'=>'string') suddenly have the post type archive stop working - I get a "Not found" message (i.e. an 404 page).

    This can be fixed by saving the permalink options to refresh the rewrite rules, but it then happens again a few weeks later (the exact schedule is unclear).

    This does not happen on sites where I don't set the rewrite option, but use has_archive => 'string' instead.

    Interestingly I've been going round installing the Rewrite Rules Inspector plugin, and on the one site that is now failed, I get "missing" rewrite rules for that CPT.

    Does anyone have any idea what's happening to my rewrite rules? Why would they go missing every few weeks? Why does it not happen with has_archive=>'string'? Any ideas?

    Thanks

    Ross

Reply

You must log in to post.

About this Topic

  • RSS feed for this topic
  • Started 2 months ago by magicroundabout
  • This topic is not resolved
  • WordPress version: 3.5.1