Roots Discourse

Archive.blade.php for custom post type

Hello everyone,

I created a plugin to rename POST to “something_else” and a plugin to create a new custom post type.

POST -> Services

add_action( 'init', 'cp_change_post_object' );
// Change dashboard Posts to News
function cp_change_post_object() {
	$get_post_type = get_post_type_object('post');
	$labels = $get_post_type->labels;
	$labels->name = 'Servizi';
	$labels->singular_name = 'Servizi';
	$labels->add_new = 'Add Servizi';
	$labels->add_new_item = 'Add Servizio';
	$labels->edit_item = 'Edit Servizio';
	$labels->new_item = 'Servizi';
	$labels->view_item = 'View Servizi';
	$labels->search_items = 'Search Servizi';
	$labels->not_found = 'No Servizi found';
	$labels->not_found_in_trash = 'No Servizi found in Trash';
	$labels->all_items = 'All Servizi';
	$labels->menu_name = 'Servizi';
	$labels->name_admin_bar = 'Servizi';
	$get_post_type->menu_icon = 'dashicons-media-document';
}

CPT -> Case

add_action( 'init', 'create_cases_cpt' );

// Here replace "your-post-type" with the actual post type, e.g., "cherry_services", "cherry-projects"
add_filter( 'case', 'case' );
function _my_rewrite_slug( $args ) {
	$args['rewrite']['slug'] = 'case'; // Replace "our-services" with your preferable slug
	return $args;
}

function create_cases_cpt() {
	register_post_type( 'case',
		array(
			'labels' => array(
				'name'               => 'Cases',
				'singular_name'      => 'Case',
				'menu_name'          => 'Case',
				'name_admin_bar'     => 'Case',
				'add_new'            => 'Add New',
				'add_new_item'       => 'Add New Case',
				'edit_item'          => 'Edit Case',
				'new_item'           => 'New Case',
				'view_item'          => 'View Case',
				'search_items'       => 'Search Cases',
				'not_found'          => 'No cases found',
				'not_found_in_trash' => 'No cases found in trash',
				'all_items'          => 'Cases',
			),

			'public' => true,
			'menu_position' => 2,
			'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields', 'page-attributes' ),
			'show_in_rest' => true,
			'taxonomies' => array( '' ),
			'menu_icon'           => 'dashicons-admin-appearance',
			'has_archive'         => true
		)
	);
}

according to what I have found BOTH of them should be compatible with basic WP hierarchy and therefore, since CPT has 'has_archive' => true , creating an archive.blade.php automatically should be invoked in a page displaying such template.

creating a single page called “services” though, keeps opening a single page

so I created a specific page-archive.blade.php template, so I could assign to “service” page and “case” page.

“service” is now OK, while “case”, even if assigned to same template, is ignoring inner code, while is loading entry-meta.blade.php page partials! why is that so?

ty!

hello!
no hints? :frowning:
don’t know if upping is allowed, but this sounds quite strange :frowning: