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)
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)
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/%postname%/
, then you can just add the pages as sub pages of your posts. More details here.
Template Post Type: page, movies
to the template header: developer.wordpress/themes/template-files-section/… – Jacob Peattie Commented Dec 31, 2018 at 15:36single-{post-type}.php
right? No what I need to pass this endpoint Post ID fromsingle-{post-type}.php
to another page. As you know the other page has no idea what is the last viewed single post – Mona Coder Commented Dec 31, 2018 at 16:22/movie/postname/details/
for each post. – Milo Commented Jan 1, 2019 at 4:56