Trailing comma causing WordPress custom post to not work as intended

I’ve got a custom post that I’m creating. It’s used as a page, and you can click on the menu item to get to it. However, in the rewite subarray, I left a trailing comma, this seemed to “break” (although no errors were present) wordpresses permalink structure when set to “pretty permalinks”. However when set to default, it would function just fine.

The offending code:

Read More
$args = array(
        'labels'               => $labels,
        'description'          => '',
        'public'               => true,
        'hierarchical'         => false,
        'exclude_from_search'  => true,
        'publicly_queryable'   => true,
        'show_ui'              => true,
        'show_in_menu'         => true,
        'show_in_nav_menus'    => true,
        'show_in_admin_bar'    => true,
        'menu_position'        => 21,
        'menu_icon'            => 'dashicons-id',
        'capability_type'      => 'page',
        'capabilities'         => array(),
        'map_meta_cap'         => true,
        'supports'             => array( 'title', 'editor', 'thumbnail', 'revisions' ),
        'register_meta_box_cb' => null,
        'taxonomies'           => array( 'profile-position' ),
        'has_archive'          => false,
        'rewrite'              => array( 'slug' => 'profile', ),
        'query_var'            => true,
        'can_export'           => true,
        'delete_with_user'     => false,
    );

    register_post_type( 'profile', $args );

    register_taxonomy(
        'profile-position',
        array( 'profile' ),
        array(
            'hierarchical' => false,
            'labels' => array(
                'name'                       => _x( 'Positions', 'taxonomy general name' ),
                'singular_name'              => _x( 'Position', 'taxonomy singular name' ),
                'search_items'               => __( 'Search Positions' ),
                'all_items'                  => __( 'All Positions' ),
                'edit_item'                  => __( 'Edit Position' ),
                'update_item'                => __( 'Update Position' ),
                'add_new_item'               => __( 'Add New Position' ),
                'new_item_name'              => __( 'New Position Name' ),
                'menu_name'                  => __( 'Positions' ),
                'view_item'                  => __( 'View Position' ),
                'popular_items'              => __( 'Popular Positions' ),
                'separate_items_with_commas' => __( 'Separate positions with commas' ),
                'add_or_remove_items'        => __( 'Add or remove positions' ),
                'choose_from_most_used'      => __( 'Choose from the most used positions' ),
                'not_found'                  => __( 'No positions found' )
            ),
            'rewrite' => array(
                'hierarchical' => false,
                'slug' => 'profiles/position',
                'with_front' => false
            ),
        )
    );

    register_taxonomy_for_object_type( 'profile-position', 'profile' );

The functioning code:

// Custom post type for profiles
    $args = array(
        'labels'               => $labels,
        'description'          => '',
        'public'               => true,
        'hierarchical'         => false,
        'exclude_from_search'  => true,
        'publicly_queryable'   => true,
        'show_ui'              => true,
        'show_in_menu'         => true,
        'show_in_nav_menus'    => true,
        'show_in_admin_bar'    => true,
        'menu_position'        => 21,
        'menu_icon'            => 'dashicons-id',
        'capability_type'      => 'page',
        'capabilities'         => array(),
        'map_meta_cap'         => true,
        'supports'             => array( 'title', 'editor', 'thumbnail', 'revisions' ),
        'register_meta_box_cb' => null,
        'taxonomies'           => array( 'profile-position' ),
        'has_archive'          => false,
        'rewrite'              => array( 'slug' => 'profile', 'with_front' => false ),
        'query_var'            => true,
        'can_export'           => true,
        'delete_with_user'     => false,
    );

    register_post_type( 'profile', $args );

    register_taxonomy(
        'profile-position',
        array( 'profile' ),
        array(
            'hierarchical' => false,
            'labels' => array(
                'name'                       => _x( 'Positions', 'taxonomy general name' ),
                'singular_name'              => _x( 'Position', 'taxonomy singular name' ),
                'search_items'               => __( 'Search Positions' ),
                'all_items'                  => __( 'All Positions' ),
                'edit_item'                  => __( 'Edit Position' ),
                'update_item'                => __( 'Update Position' ),
                'add_new_item'               => __( 'Add New Position' ),
                'new_item_name'              => __( 'New Position Name' ),
                'menu_name'                  => __( 'Positions' ),
                'view_item'                  => __( 'View Position' ),
                'popular_items'              => __( 'Popular Positions' ),
                'separate_items_with_commas' => __( 'Separate positions with commas' ),
                'add_or_remove_items'        => __( 'Add or remove positions' ),
                'choose_from_most_used'      => __( 'Choose from the most used positions' ),
                'not_found'                  => __( 'No positions found' )
            ),
            'rewrite' => array(
                'hierarchical' => false,
                'slug' => 'profiles/position',
                'with_front' => false
            ),
        )
    );

    register_taxonomy_for_object_type( 'profile-position', 'profile' );

the offending line:
'rewrite' => array( 'slug' => 'profile', )
the functioning line(s):
'rewrite' => array( 'slug' => 'profile')
'rewrite'=> array( 'slug' => 'profile', 'with_front' => false )

To note – once the comma is removed, with or without the second entry into the rewrite array, expected functionality returns and I can access the page. My understanding is that php ignores trailing commas and it is technically okay to do so (although I typically like to avoid it and this was an error on my part in regards to personal preference).

So what could be causing the website to return to home page when there is a trailing comma?

Related posts