how to enable comments for custom posts

Shortlink:

Today i will tech you, how to enable comments form/comments_template in custom posts. It’s very easy this work. just follow below coding…

I think you know how to create custom post, but if you don’t know then i will share you, just see below code for normal custom post register.


register_post_type( 'portfolios',
array(
'labels' => array(
'name' => __( 'Portfolio Items' ),
'singular_name' => __( 'Portfolio Item' ),
'add_new_item' => __( 'Add New Portfolio Item' )
),
'public' => true,
'supports' => array('title', 'editor', 'custom-fields', 'thumbnail'),
'has_archive' => true,
'capability_type' => 'page',
'rewrite' => array('slug' => 'item'),
'taxonomies' => array('post_tag')

)
);

just you can see support list


'supports' => array('title', 'editor', 'custom-fields', 'thumbnail'),

Just input comments in support lists, example:


'supports' => array('title', 'editor', 'custom-fields', 'thumbnail', 'comments'),

if you input comments then see full code is below


register_post_type( 'portfolios',
array(
'labels' => array(
'name' => __( 'Portfolio Items' ),
'singular_name' => __( 'Portfolio Item' ),
'add_new_item' => __( 'Add New Portfolio Item' )
),
'public' => true,
'supports' => array('title', 'editor', 'custom-fields', 'thumbnail', 'comments'),
'has_archive' => true,
'capability_type' => 'page',
'rewrite' => array('slug' => 'item'),
'taxonomies' => array('post_tag')

)
);

then you can see enable comments form in custom post. but you don’t see single posts, because you need to call comments template.

you will call below code, where are locations do you want to show comments form.


<?php comments_template( '', true ); ?>

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!




%d bloggers like this: