[wp-hackers] custom post types and child pages
johnbillion+wp at gmail.com
Sat Apr 30 19:46:57 UTC 2011
On 30 April 2011 20:13, Steve Taylor <steve at sltaylor.co.uk> wrote:
> Say I have "projects" as a CPT. The archive page is defined as living here:
> Now, this is also an actual WP page, which I use to manage the intro
> to the archive list etc. The URL for a project will of course be:
> But what if they have some other information about projects and they
> want a standard WP page here:
> This gives a 404 - presumably because the rewrite rules signal that
> we're looking for a project and there's no project with the slug
> For now I've advised that they make anything planned as a child page
> of /research/projects/ into a sibling page - not too much of a
> sacrifice, and very easy. However, I wonder if there's a way to step
> into the rewriting process and say, "If there's no CPTs found under a
> CPT archive URL, look for child pages of the page that has the same
> URL as the CPT archive"? If anyone's achieved this, do let me know.
I have the same situation. What I done was to add a filter to the
rewrite rules array and add a couple of rewrite rules that match the
page slugs . It doesn't automatically work for all pages, but as
it's a project for a client know there will only ever be those two
child pages. If we end up adding other pages then I'll just add their
slugs to the array and regenerate the rewrite rules.
It would be neat to come up with an automated solution. It could
probably be done fairly easily (I'm thinking along the lines of
fetching all child pages of page 'foo' and adding them to the rewrite
rules array and flushing the rules when new pages are added).
> CPT SINGLE POST VIEWS
> The other issue is that the ideal situation for this project is to
> have child pages of CPTs. So if there's a project at this URL:
> As well as the main page, there might be an extra page for this project:
> Or more... The whole idea doesn't make sense to me in WP terms - that
> child couldn't be a page with a CPT as a parent.
> I've tried making the CPT hierarchical, but it doesn't seem to make
> sense to have a project as a child of a project for what I'm talking
> about above. Besides, the child page throws a 404 :-\
For some reason hierarchical CPTs don't get hierarchical URLs. This
has always been the case and I'm not sure why.
At first thought allowing inter-mixing of CPTs and pages doesn't make
a whole lot of sense, but I can see a need for it. I remember back in
the old days (when rewrite rules were in .htaccess) we had a separate
rewrite rule for every page on the site. I'm not for a moment
suggesting we go back to that by defauly, but it would offer a
solution for those who needed it.
More information about the wp-hackers