Why will comments not remain open on custom post types?

Question

I have a WP install which makes use of default posts and of one custom post type (reviews). Discussion settings allow comments on both these post types. The comment form is present when viewing posts but I am getting “comments are closed” on the CPTs front-end.

If I edit the individual reviews I can see that “Allow comments” is not checked. If I check this and hit “Update” it reverts to unchecked (this does’t happen with “Allow trackbacks and pingbacks”).

This unchecking also happens if I “Quick Edit” in the All Reviews admin page too.

Comments which are already in the database are still visible using comments_template();, but the form will not appear on CPTs because comments cannot be enabled.

I have made sure that “Admin > Settings > Discussion > Allow people to submit comments on new posts” is checked. I have unchecked/rechecked it as per this question but it has made no difference.

The CPT is declared in functions.php as follows:

add_action('init', 'all_custom_post_types');

function all_custom_post_types() {
    $types = array(
        array(
            'the_type' => 'review',
            'single' => 'Review',
            'plural' => 'Reviews'
        ),
    );

foreach ($types as $type) {
    $the_type = $type['the_type'];
        $single = $type['single'];
        $plural = $type['plural'];
        $labels = array(
            'name' => _x($plural, 'post type general name'),
            'singular_name' => _x($single, 'post type singular name'),
            'add_new' => _x('Add New', $single),
            'add_new_item' => __('Add New '. $single),
            'edit_item' => __('Edit '.$single),
            'new_item' => __('New '.$single),
            'view_item' => __('View '.$single),
            'search_items' => __('Search '.$plural),
            'not_found' =>  __('No '.$plural.' found'),
            'not_found_in_trash' => __('No '.$plural.' found in Trash'),
            'parent_item_colon' => '',
        );
        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'hierarchical' => true,
            'has_archive' => true,
            'menu_position' => 5,
            'supports' => array('title','editor','thumbnail','comments'),
            'show_in_menu' => true,
            'show_in_nav_menus' => true,
            'taxonomies' => array('category','post_tag'),
        );
        register_post_type($the_type, $args);
    }
}

comments are included under supports in the $args here.

Why would this be happening and how can I fix it?

0
mtm 5 months 2022-06-24T07:02:28-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse