I want to be able to have a link like this, site.com/my-custom-type-slug/single-custom-post-name/stats/, where /stats should contain the /my-custom-type-slug page content and when I add content to the /stats page, it should be added after the parent’s content.
The /stats page should be available for every page created within my CPT, for example /my-custom-type-slug2, /my-custom-type-slug3, and so on, to have the /stats.
I’m thinking that a solution can be to create a page named stats and assign a custom template, but the problem is how can I create the additional content for every new post which I’m creating?
This would be easy if I didn’t need the comments to be activated because I was doing it like this:
Add a custom WYSIWYG field inside my posts with ACF plugin, then create an endpoint:
function wpa121567_rewrite_endpoints(){
add_rewrite_endpoint( 'stats', EP_PERMALINK );
}
add_action( 'init', 'wpa121567_rewrite_endpoints' );
After this my URL would look like this:
site.com/your-custom-type-slug/single-custom-post-name/stats/
Then in my single-{cpt}.php
template I can check if the request is for stats, and include or output the desired data:
if( array_key_exists( 'stats', $wp_query->query_vars ) ){
// the request is for the comments page
}
else {
// the request is for the main post
}
This solution is not working for me because I can’t activate comments on /stats because I’m using an endpoint to create it.
As a conclusion, what I need is two separate sets of comments for both the parent and “/stats” page. Any suggestions on how to achieve this?