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

Mike Little wordpress at zed1.com
Tue Jul 3 01:17:53 UTC 2012


On 2 July 2012 23:11, Paul Gibbs <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/


More information about the wp-hackers mailing list