I'm coming back to WordPress after quite a hiatus (and it's not my normal CMS framework), and I'm working with custom post types for the first time.
I'd like to have 2 page templates that support section pages with URLs such as:
And then have 2 single post templates -- one for an apples custom post type, and one for an oranges custom post type -- that support URLs such as:
But when I created templates such as:
…I found that the page URL was rendering fine but single post URLs were returning 404.
I realised that, when registering the custom post types, adding
'with_front' => false as an argument of
rewrite enabled single post URLs to render, but then of course the section page URL didn't!
The solution I have at the moment is to register the custom post types in the singular form of the custom post keyword, so now I have:
Which means the corresponding URL schema has to be a mixture of plural (for the section page) and singular (for the custom post type):
I can live with this if I have to, but I'd rather have the URL schema be consistently plural.
I'd be grateful of any suggestions for how to do things differently.
Update: as requested, here's an example of how I'm registering one of the custom post types (in the singular form but with a plural Admin menu label)…
register_post_type( 'apple', array( 'labels' => array( 'name' => __( 'Apples' ) ), 'taxonomies' => array('category'), 'public' => true, 'rewrite' => array( 'slug' => 'apple', 'with_front' => false ), 'has_archive' => true ));