• I’ve just updated both WP and Custom Post Templates to the latest versions.

    Previously, CPT was picking up templates from both a child theme and its master; the list generated contained whatever templates were found in both themes, which is exactly how you (well, we) would want it to be.

    Now, however, it’s only picking up what’s found in the child theme…so we get an incomplete list, unless we copy duplicate files from the master theme into the child.

    From looking at the code, I see that the get_post_templates function has changed quite a bit. Has it lost the ability to handle the master/child relationship as before? Is that intentional or a bug?

    Any help will be gratefully received! Many thanks.

    https://www.ads-software.com/extend/plugins/custom-post-template/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ig_communitysites

    (@ig_communitysites)

    For the benefit of anyone else with the same problem, I’ve currently fixed it with the following changes…

    protected function get_post_templates()
    	{
    		$theme = wp_get_theme();
    
    		// N.B. No caching, even though core Page Templates has that.
    		// Nacin advises:
    		// "ultimately, "caching" for page templates is not very helpful"
    		// "by default, the themes bucket is non-persistent. also, calling
    		//  get_page_templates() no longer requires us to load up all theme
    		//  data for all themes so overall, it's much quicker already."
    
    		$post_templates = array();
    
    		$files = (array) $theme->get_files( 'php', 1 );
            // ikg/commsites - get files from the master theme too and combine the arrays
            if (! empty($theme->template)) {
                $master = wp_get_theme($theme->template);
                $files = array_merge($files, (array) $master->get_files( 'php', 1 ));
            }
            // ikg/commsites - end
    
    		foreach ( $files as $file => $full_path ) {
    			$headers = get_file_data( $full_path, array( 'Template Name Posts' => 'Template Name Posts' ) );
    			if ( empty( $headers['Template Name Posts'] ) )
    				continue;
    			$post_templates[ $file ] = $headers['Template Name Posts'];
    		}
    
            // ikg/commsites - because we combined the arrays earlier, we now want to sort things
            sort($post_templates);
    
    		return $post_templates;
    	}

    That’s odd. I’ve come to the support forum because I have the opposite problem. I just updated to 1.5 from 1.4 and have found that I’m now getting both parent and child theme templates which I don’t actually want.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Custom Post Template] Templates not being picked up from master theme’ is closed to new replies.