0

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 doesn'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?

EDIT

I have fixed this by registering another CPT and using that instead. The comments issue is only affecting the posts with the specific type of review. I'm not posting this as an answer because to my mind it is a workaround and not a solution.

Presumably something got logged somewhere (in the database?) and I haven't been able to find or flush it. I'd still be interested in what this might be and how I could have avoided it.

4
  • 1
    Sounds like a theme-specific issue.. Are you using a custom theme? Have you tried searching for comments_open in all PHP files in the theme folder (wp-content/themes/your-theme)? Maybe there's a code somewhere which used that hook, or another hook/way, to disable comments (for certain post types).
    – Sally CJ
    Jun 24 at 15:23
  • thanks sally, yup it's a custom theme – i've just done a search throughout for comments_open haven't found it anywhere. it's very strange. it was working at one point, and i'm not sure what's changed. i wonder if there's something in the database that needs flushing?
    – mtm
    Jun 25 at 12:15
  • I don't know.. but you can try deactivating plugins and if that doesn't help, then if you can share your theme (.zip), I can help you check if it's the one causing the issue.
    – Sally CJ
    Jun 25 at 16:22
  • thanks sally. having fixed this now by replacing the CPT the issue would need recreating for me to send you a theme to troubleshoot, so perhaps it's not worth either of our time at this point. i really appreciate the offer though.
    – mtm
    Jun 28 at 13:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.