custom post types – Uncaught Error: Call to a member function add_rewrite_tag() on null in \wp-includes\rewrite.php:176

Question

When I add the second post type (program), I get following error
Uncaught Error: Call to a member function add_rewrite_tag() on null in D:\Courses\Web Dev – Practice\XAMPP\htdocs\fictional-university\wp-includes\rewrite.php:176

My code in mu plugin is

<?php
// SECTION: EVET POST TYPE
function university_post_types()

// EVENT POST TYPE
{
    // register_post_type('Name of post type',array of options to describe post type );
    register_post_type('event', array(
        'show_in_rest' => true,
        'supports' => array('title', 'editor', 'excerpt'),
        'rewrite' => array('slug' => 'events'),
        'has_archive' => true,
        'public' => true,
        'labels' => array(
            'name' => 'Events',
            'add_new_item' => 'Add New Event',
            'edit_item' => 'Edit Event',
            'all_items' => 'All Events',
            'singular_name' => 'Event',
        ),
        'menu_icon' => 'dashicons-calendar',
    ));
};
// Program Post Type
{
    // register_post_type('Name of post type',array of options to describe post type );
    register_post_type('program', array(
        'show_in_rest' => true,
        'supports' => array('title', 'editor', 'excerpt'),
        'rewrite' => array('slug' => 'programs'),
        'has_archive' => true,
        'public' => true,
        'labels' => array(
            'name' => 'Programs',
            'add_new_item' => 'Add New Program',
            'edit_item' => 'Edit Program',
            'all_items' => 'All Programs',
            'singular_name' => 'Program',
        ),
        'menu_icon' => 'dashicons-awards',
    ));
};

add_action('init', 'university_post_types');

0
Huzaifa Qayyum 4 months 2022-08-01T02:29:54-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse