0

I am following the wp doc for adding a custom post type:

function create_post_type() {
  register_post_type( 'startup',
    array(
      'labels' => array(
        'name' => __( 'Startup' ),
        'singular_name' => __( 'Startup' )
      ),
      'public' => true,
      'has_archive' => false,
    )
  );
}
add_action( 'init', 'create_post_type' );

I have made single-startup.php in themes root but it doesn't load for any post with that type.

For example if I go to test.com/startup/my-page This will show index.php contents.

I know there are several questions like this, but none of them worked for me. I don't know why.

enter image description here

I have random string in single-startup.php

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod...

When I visit custom post page: 'abc.com/startup/some-startup-page/' I see same content as 'abc.com/' i.e index page.

However when I visit a default type post/page i.e 'abc.com/test-post/' It works perfectly. single-post.php and page.php are loaded correctly.

Its just single-startup.php that is causing problem.

enter image description here enter image description here

  • When you say that you get the "index.php" contents, do you mean that you're seeing the index.php template, but the correct post is loaded within the loop? Or you're seeing the index.php template loaded with some other content? – Jacob Peattie Nov 29 '17 at 9:13
  • when I visit the permalink echoed by a startup post type like 'abc.com/startup/some-startup-page/' I see same content as 'abc.com/' i.e index page – Waleed Nov 29 '17 at 13:36
  • please check the updated question, ty – Waleed Nov 29 '17 at 13:41
  • Are you actually redirected or does the URL stay the same? – Jacob Peattie Nov 29 '17 at 13:45
  • No redirections. I have attached more snapshots. – Waleed Nov 29 '17 at 13:50
2

This might be completely off the mark, but have you tried regenerating your .htaccess file, after creating the new post type.

This usually results in some awkward behaviour.

To do this, simply go to settings->permalinks and hit "save".

In terms of the template structure, everything does seem fine.

  • I didn't even have to hit save button. Only going to permalink page made it work. – Waleed Nov 29 '17 at 15:05
  • Glad to be of assistance :) – Daniel Fonda Nov 29 '17 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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