Using a template file for a specific custom URL


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:

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!

, , , pdlbibek 2 years 2020-01-10T08:39:12-05:00 0 Answers 85 views 0

Leave an answer