Having a Custoom Post Type called movies, I am able to get the current Post ID in my single-movies.php template. Now can you please let me know how I can pass this post ID from the single template to a custom page template like page-postDetail.php basically what I want to do is adding some more details to the post in the custom page (Like having multi single template foe one custom post type)

  • If you want a custom page template to be available for a for a custom post type you can do this in 4.7+ by adding Template Post Type: page, movies to the template header: developer.wordpress.org/themes/template-files-section/… Dec 31, 2018 at 15:36
  • How are you currently acquiring the post ID? And can you not do the same thing in the other template?
    – Tom J Nowell
    Dec 31, 2018 at 15:54
  • Thanks guys for commenting out. @JacobPeattie, This is not what I am looking for. What I need is a page which getting Post ID of last viewed single template. @Tom, lets say users clicked a Movie from all custom Post type template this will automatically land in the single-{post-type}.php right? No what I need to pass this endpoint Post ID from single-{post-type}.php to another page. As you know the other page has no idea what is the last viewed single post
    – Mona Coder
    Dec 31, 2018 at 16:22
  • What about using a rewrite endpoint? You would have a URL like /movie/postname/details/ for each post.
    – Milo
    Jan 1, 2019 at 4:56

1 Answer 1


First of all, (you probably know this but..) you are fighting how WP is intended to work. You can not get the post ID directly in your custom page template because it is not displaying the post. So you will have to, as you said, send the post ID to the page template.

The best way I can think of, to do it this way, is to send it to the new page via GET or POST. The most simple way would be to add a query string to whatever link goes to the sub-page containing the ID, which might look like this ?post_id=123. Then, you can parse the URL query string to get the ID and use it as needed.

Alternatively, you could make your CPT (Custom Post Type) structure hierarchical and set your permalink structure to example.com/%postname%/, then you can just add the pages as sub pages of your posts. More details here.

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.