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

Mike Little wordpress at zed1.com
Tue Jul 3 09:25:19 UTC 2012


On 3 July 2012 07:23, Paul Gibbs <paul at byotos.com> wrote:

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

The comment paging isn't always added: you need to make sure you don't have
comments in the supports parameter (obviously), but if you turn off too
many things, it seems to default to turning them back on, somewhere I
couldn't trace (I didn't try too hard).

This example plugin for custom post type "cpt"
http://pastebin.com/FCDwJr2i produces these rules:

    'cpts/?$' => 'index.php?post_type=cpt',
    'cpts/page/([0-9]{1,})/?$' =>
'index.php?post_type=cpt&paged=$matches[1]',
    'cpt/.+?/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]',
    'cpt/.+?/attachment/([^/]+)/trackback/?$' =>
'index.php?attachment=$matches[1]&tb=1',
    'cpt/.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' =>
'index.php?attachment=$matches[1]&feed=$matches[2]',
    'cpt/.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' =>
'index.php?attachment=$matches[1]&feed=$matches[2]',
    'cpt/.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' =>
'index.php?attachment=$matches[1]&cpage=$matches[2]',
    'cpt/(.+?)/trackback/?$' => 'index.php?cpt=$matches[1]&tb=1',
    'cpt/(.+?)/page/?([0-9]{1,})/?$' =>
'index.php?cpt=$matches[1]&paged=$matches[2]',
    'cpt/(.+?)(/[0-9]+)?/?$' =>
'index.php?cpt=$matches[1]&page=$matches[2]',

The attachments ones just seem to be always added as does the trackback
one. So you may need to add code to strip those explicitly.
Or else some extra magic with the ep_mask setting in the rewrite param (I
ended up setting it to 0 at some point).


Mike
-- 
Mike Little
http://zed1.com/


More information about the wp-hackers mailing list