Custom Post Type not using base.php....?

[sage8 question]

I’ve been using Sage for ages, and am officially stumped on this scenario…

I always use CTPs, but for some reason, this site is giving me issues.

There’s a CTP set up, and I’m attempting to display the archive page ( It seems to skip the base.php and render the index.php directly - so I have a page that is showing the correct content, but isn’t using the wrapper that every one page uses. I have no idea why.

There was pages with the same name as the custom post type, so I’m wondering if there’s some sort of weird conflict going on… I have deleted those pages (including from the trash) and flushed the permalinks…

Here’s the code for the CPT - (this was created using CPT UI previously, before my involvement).

	$args = array(
	"label" => __( 'My CPT', 'sage' ),
	"labels" => $labels,
	"description" => "",
	"public" => true,
	"publicly_queryable" => true,
	"show_ui" => true,
	"show_in_rest" => false,
	"rest_base" => "",
	"has_archive" => true,
	"show_in_menu" => true,
			"exclude_from_search" => false,
	"capability_type" => "post",
	"map_meta_cap" => true,
	"hierarchical" => false,
	"rewrite" => array( "slug" => "my-cpt", "with_front" => true ),
	"query_var" => true,		
	"supports" => array( "title", "editor", "excerpt", "revisions", "author", "page-attributes" ));

register_post_type( "my-cpt", $args );

Any advice?

There shouldn’t be anything in the code for registering a post type that would cause this to happen. There’s some other functionality on your site/theme that’s causing this.

If you were to try this on a fresh install you wouldn’t be able to reproduce your error.

1 Like

I have done a fresh install of sage - and I am getting the same thing…

What about a fresh WordPress installation with a blank database and no plugins…?

Not sure the newer SageWrapping class recognizes custom post types. I believe you still need to add the following to lib/wrapper.php?

// Source:
add_filter('sage/wrap_base', __NAMESPACE__ . '\\sage_wrap_base_cpts'); // Add our function to the sage/wrap_base filter

function sage_wrap_base_cpts($templates) {
  $cpt = get_post_type(); // Get the current post type
  if ($cpt) {
     array_unshift($templates, 'base-' . $cpt . '.php'); // Shift the template to the front of the array
  return $templates; // Return our modified array with base-$cpt.php at the front of the queue

I just did a dummy base-my-cpt.php and used your CPT snippet and it worked after I added the above to lib/wrapper.php.

You might want to regenerate the CPT arguments and labels inside a namespace-ed function as well. I use GenerateWP to whip those up real quick.