I have custom post type posts with the . character in the post_name field (thus the permalink) and it does not resolve to the correct page template. In this case instead of going to single-cptslug.php the permalink resolves to index.php. The post_name field gets it's data from a custom field and is updated via a custom query:

$wpdb->query("UPDATE " . $wpdb->prefix . "posts SET post_name = '" . $slug . "' WHERE ID = " . $post_id);

Where $slug is something like

I'm thinking the solution here may involve modifying the .htaccess file but I'm not sure and also have little to no .htaccess experience. Any help appreciated!

  • It might be easiest to set them up as custom page templates and then just select them from the dropdown list in the publish metabox.
    – WebElaine
    Apr 10, 2018 at 20:34
  • I should have mentioned that even when doing that it still doesn't resolve to the right page template (still goes to index.php) if there's a dot . in the post_name field (thusly the permalink as well) Apr 10, 2018 at 20:40
  • this sometimes happens when WordPress is confused about what type of request it is. what are your cpt rewrite settings? also, it could be a sanitization issue, maybe try this plugin, which will allow dots in slugs.
    – Milo
    Apr 10, 2018 at 22:45
  • it's just rewriting the slug to the same slug. the problem with that plugin is that it alters the sanitize_title function for everything not just this isolated case. hence why I've avoided using this technique. Apr 10, 2018 at 22:53

1 Answer 1


I wound up using the index_template filter to load the right template when the CPT single page is being incorrectly redirected to the index and $_SERVER['REQUEST_URI'] contains the slug of the CPT. Like so:

add_filter('index_template', 'wpse300393_resolve_cpts_with_dots_in_name');

function wpse300393_resolve_cpts_with_dots_in_name($templates = ''){
    if( strpos($_SERVER['REQUEST_URI'], 'artwork') !== false ){
        $templates = locate_template( 'single-artwork.php' );
    elseif( strpos($_SERVER['REQUEST_URI'], 'artist') !== false ){
        $templates = locate_template( 'single-artist.php' );
    return $templates;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.