I was trying to use a custom URL to load a page template for single-events.php
without rewriting the default URL format. I am using filter template_include
to load the template like this:
add_filter('template_include','include_template_for_single_event',99);
function include_template_for_single_event($template)
{
//check_for_single_event() will check if the current url = custom url
if( check_for_single_event() ){
$new_template = locate_template(array('single-events.php','single.php'));
if($new_template)$template = $new_template;
}
return $template;
}
The issue with this is that the contents of the single cpt within the loop is not loading which means there is no data for the single cpt such as get_the_ID()
, have_posts()
etc
Edit:
I do have a default link for a single post of a custom post type
example.com/nepal/events/visit-year-2020
Now, I want to load this same page template with URL
example.com/nepal/events/visit-year-2020/2020-01-10.
P.S. client still want the default URL and this new URL with every date available appended to the end.
example.com/nepal/events/visit-year-2020
Now, I want to load this same page template with URLexample.com/nepal/events/visit-year-2020/2020-01-10
. P.S. client still want the default URL and this new URL with every date available appended to the end.