Enable comments in custom post type

2

I have a custom post type called "news" and I am trying to include comments, and I do not get it.

I will tell you everything I have done and nothing has worked:

include in functions.php

function default_comments_off( $data, $postarr ) {
     if( $data['post_type'] == 'page' || $data['post_type'] == 'noticias' ) {
          //New posts don't have an ID - So this checks if the post is new or already exists
          if( !($postarr['ID']) ){
               $data['comment_status'] = 1; //0 = false | 1 = true
          }
     }
     return $data;
}
add_filter( 'wp_insert_post_data', 'default_comments_off', '', 2);

When creating the custom post type, include support comments

function noticias(){
    $labels = array(
        'name' => 'Noticias',
        'singular_name' => 'Noticia',
        'add_new' => 'Agregar nueva noticia',
        'all_items' => 'Todas las noticias',
        'add_new_item' => 'Agregar nueva noticia',
        'edit_item' => 'Editar',
        'new_item' => 'Agregar nueva noticia',
        'view item' => 'Ver',
        'search_item' => 'Buscar',
        'not_found' => 'Noticia no encontrada',
        'not_found_in_trah' => 'Noticia no encontrada en la papelera'
        );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'has_archive' => true,
        'publicly_queryable' => true,
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'supports' => array(
            'title',
            'thumbnail',
            'editor',
            'author',
            'comments'),
        'menu_position' => 6,
        'exclude_from_search' => true,
        'menu_name' => 'Noticias',
        'menu_icon' => 'dashicons-format-aside',
        'can_export' => true
        );
    register_post_type('noticias', $args);
  flush_rewrite_rules();
}
add_action('init', 'noticias');

In settings > comments , disable the option "Allow comments on new entries", save, re-enable, re-save.

    
asked by MarisabelGC 07.09.2017 в 18:41
source

0 answers