I seem to have exhausted all the references on this subject, but if this is a duplicate post my apologies.
I am having a problem where ANY custom post page displays the 404.php file’s error content, regardless of method of getting there. This includes simply going to something as rudimentary as http://domain.com/?p=123.
I have done the following:
- Flushed permalink settings (though I don’t think it’s a permalink problem)
- Deleted .htaccess and recreated it by going to settings -> permalinks
- Specifically created a single-[name].php file for any given type
- Disabled all plugins
- Checked for any page/taxonomy name conflicts (still fails even w/ random name)
- Checked server logs for errors (none since troubleshooting began)
- Uploaded entire theme to different WP install
All to no avail.
I have reduced the custom post registration to as simple a function as I can conjure:
add_action('init', 'init_sample');
function init_sample() {
$args = array(
'public' => true,
);
register_post_type( 'sample' , $args );
}
But neither this nor any other combinations of arguments seem to help.
Even clicking the “View Post” link in admin takes one to a 404 page.
I can, however, retrieve custom posts via query with no problem.
I’m running WP v3.2.1.
If I had to guess, I’d say there’s something elsewhere in the theme fouling things up, but I have no idea where to go to find that out – could anyone provide some suggestions on where to even look to troubleshoot this issue?
As soon as I was done asking the question, I went to close functions.php for the night and happened to notice the custom post types were being registered along with other admin-specific features inside an
if (is_admin()) {
evaluator. Taking them out of that did the trick.Reasonably enough, it looks like custom posts MUST be registered in a publicly-accessible manner.
There must be some law that, regardless of hours of effort leading up to a Stack Exchange question, the solution will present itself within minutes after it’s asked.
Custom Post types are “registered” in code, not in the database (like custom taxonomies to name another example). So wrapping such code in a
if ( is_admin() )
statements blends it away from public facing queries as your theme or plugin doesn’t tell the public$wp_query
object that there’s such a thing as your cpt or custom taxonomy. This also means that stuff like the$wp_template_hierarchy
won’t work if you don’t “register” it for every page view.