Using a template file for a specific custom URL

Question

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

Will appreciate your help. Thanks!

0
, , , pdlbibek 11 months 0 Answers 75 views 0

Leave an answer