[wp-hackers] how to stop custom post type creating attachment/trackback/feed rewrite rules?

Paul Gibbs paul at byotos.com
Tue Jul 3 06:23:58 UTC 2012


Hi Kevinjohn, Mike, 

Thanks for the advice. I'll investigate unsetting the attachment rewrite rules manually and seeing how well that works.

Mike, about 'feed' vs 'feeds'. Good spot, and this does seem like a bug. Setting that too removes the following as you'd expect: 
achievements/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$



achievements/(.+?)/(feed|rdf|rss|rss2|atom)/?$





It does not affect (these still here): achievements/(.+?)/trackback/?
achievements/(.+?)/comment-page-([0-9]{1,})/?$

Looking at WP_Rewrite::generate_rewrite_rules, it looks like those two rules are always added to the post type.
In any case, this has me down from 11 rewrites to 9 rewrites so far, and I'm really pleased about that. Thanks for the help.

-- 
Paul Gibbs


On Tuesday, 3 July 2012 at 02:17, Mike Little wrote:

> On 2 July 2012 23:11, Paul Gibbs <paul at byotos.com (mailto:paul at byotos.com)> wrote:
> 
> > When registering a custom post type ("achievements") with the following
> > arguments, WordPress creates more rewrite rules than I want. My concern is
> > causing the unnecessary rules to be generated, and the possibility of a
> > theme's generic template files being used. For example, I don't want any
> > feed for my post type, but right now I can type the URL in and get fetch a
> > RSS feed. I'm on WP 3.4.
> > 
> > How do I stop these rules being generated?
> > 
> > 
> > // 'rewrite'
> > $rewrite['achievement'] = array(
> > 'feeds' => false,
> > 'pages' => false,
> > 'slug' => dpa_get_achievement_slug(),
> > 'with_front' => false,
> > );
> > // 'supports'
> > $supports['achievement'] = array(
> > 'editor',
> > 'revisions',
> > 'thumbnail',
> > 'title',
> > );
> > 
> > 
> > Using the Rewrite Rules Inspector plugin, I see WordPress has generated
> > the following rewrite rules which I do not require:
> > 
> > ATTACHMENTS + COMMENT PAGING:
> > achievements/.+?/attachment/([^/]+)
> > achievements/.+?/attachment/([^/]+)/trackback/?$
> > achievements/.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$
> > achievements/.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$
> > achievements/.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$
> > 
> > TRACKBACK + FEED + COMMENT PAGING:
> > achievements/(.+?)/trackback/?$
> > achievements/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$
> > achievements/(.+?)/(feed|rdf|rss|rss2|atom)/?$
> > achievements/(.+?)/comment-page-([0-9]{1,})/?$
> > 
> 
> 
> Paul,
> 
> It looks like there is a bug. But firstly, I think you will need to deal
> with the attachment feeds manually. Attachments are treated as an
> independent type which then gets tacked on to other types. Perhaps
> KevinJohn suggestion?
> 
> But the main CPT shouldn't get the feeds created. The problem comes from
> the fact that register_post_type() looks at $args->rewrite['feeds'] to see
> whether to add feed rules or not. But then it calls add_permastruct()
> passing $args->rewrite which calls WP_Rewrite::add_permastruct() which in
> turn merges those args with an array of defaults using $defaults['feed'] --
> with no 's';
> 
> That must be a bug but I don't know which is correct. I suspect the
> singular is correct. (it ought to be older than CPTs)
> 
> So, for now if you add both 'feeds' => false and 'feed' => false to your
> rewrite array, you won't get the trackback/feed/comment paging.
> 
> It's too late here to put together a proper bug report on trac right now,
> I'll try to get to it tomorrow. Feel free to report it ahead of me.
> 
> 
> Mike
> -- 
> Mike Little
> http://zed1.com/
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com (mailto:wp-hackers at lists.automattic.com)
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> 
> 




More information about the wp-hackers mailing list