Some solution to create a custom template for (page 404) for specific custom post type.
-
if it's a 404 then how would you know which custom post type it was? – Tom J Nowell♦ Apr 3 '18 at 14:07
-
that is the point! I have seen that some pages made in wordpress, handle different 404, for different types of post – Juan David Apr 3 '18 at 14:15
-
1I haven't, do you have examples you can put in your question? – Tom J Nowell♦ Apr 3 '18 at 14:54
This is going to track only post_type
query var, but you also can add checks for query_vars
of all your post_types or only ones you would like to get a custom 404 page for.
add_filter( '404_template_hierarchy', function( $templates ) {
global $wp_query;
if ( '' !== $wp_query->get('post_type') ) {
array_unshift( $templates,
sprintf( '%s-404.php', $wp_query->get('post_type') ) );
}
return $templates;
});