Custom Post Type with Template – Template is not used
Question
i created a custom post tpye
function ABECrm_post_type() {
$labels = array(
'name' => __( 'Agenden', 'ABECrm' ),
'singular_name' => __( 'Agenda', 'ABECrm' ),
'add_new' => __( 'Neue Agenda', 'ABECrm' )
);
$args = array(
'label' => __( 'agenda', 'ABECrm' ),
'description' => __( 'Hier werden die Agenda-Seiten eingetragen', 'ABECrm' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'custom-fields', 'page-attributes' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 20,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
'show_in_rest' => true,
'rewrite' => array('slug' => 'Schulungen'),
'menu_icon' => 'dashicons-admin-page'
);
register_post_type( 'agenden', $args );
}
add_action( 'init', 'ABECrm_post_type', 0 );
then a template Agenden.php:
<?php
/*
Template Name: ABECrm Agenda
Template Post Type: Agenden, page
*/
?>
Then i create a new page:
$my_post = array(
'post_title' => $mytitle,
'post_status' => 'publish',
'post_type' => 'Agenden',
'post_name' => $myurl,
'page_template' => 'Agenden.php',
);
// Insert the post into the database
$ID = wp_insert_post( $my_post );
The result is a page under “Agenden”. If i do quickedit it shows that the template is choosen – but if i call the page template is not used. What did i wrong?
If i use the template on normal page – all is right.
0
custom-post-types, page-template
4 years
2020-02-18T08:38:25-05:00
2020-02-18T08:38:25-05:00 0 Answers
54 views
0
Leave an answer