Enable comments on Custom Post Types
I have read around the forums but cannot make comments visible on custom post types.
I have added this code to my CPT.php:
'supports' => array('title','editor','thumbnail', 'author', 'comments') );
But from what I have read I need to add something to my themes functions.php too but can’t isolate what code to add to where from examples I have seen. My functions.php code is:
Any help would be great, Thanks!
I think you need to include a call to comments_template() in your theme. Look at TwentyTen/single.php, for example.
Thanks for the reply, I have tried adding
<?php comments_template( '', true ); ?>
to my single-review.php but I cannot figure out how to successfully implement this, I dont know where it is supposed to go. I found that call to comments_template in Twenty Ten.
Here is my single-preview.php code:
Any help would be great!
Ok, I have found where to insert
<?php comments_template( '', true ); ?>
and now when I click on a review there is a piece of text reading “Comments are closed.” So I know that the single-review is prepped for comments, however, from the admin side when I write a new review (custom post type) and click screen options at the top there is no check box for comments to be activated. Any idea how I add this functionality to my custom post type?
AFAIK, you should have that already with the ‘supports’ option.
It might be worth trying the Custom Post Type UI plugin instead of registering the post type yourself.
Ok I have now installed that plugin and it seems that I can now create custom post types. I have the theme installed that already has custom post types but I cant seem to see how to edit those using the plugin?
thanks for your help and the heads up!
You will need to reregister the type using the plugin before you can edit it. You will need to remove all the code in your functions.php that registers the type and register it using the plugin.
Bump – Any luck with this PhillShaw? I have wp e-commerce installed and it has its own custom post type for products, but there is no comment box on the product posts!!! i want to know if this custom post type ui plugin can help…anyone know how i can add comment boxes to the product posts?
Comments on CPTs works out of the box.
If you’re trying to change options on an existing CPT, however, you have either deregister and reregister the CPT (which doesn’t work the way I think it should) or edit the source code.
Wp E Commerce supposedly can do this on it’s own: http://docs.getshopped.org/resource/chapter-2-enabling-and-disabling-comments/
I had the same issue, I’m using Custom Post Type UI, and already had made and began using my CPT, so resetting and starting over wasnt an option.
I happen to have access to my db, using CPanel/phpAdmin
I looked up my cpt type in the POSTS table, and went through each existing and ‘post’ and changed COMMENT_STATUS from CLOSED to OPEN.
Now, my comments are displaying. I had the comments option enabled, but not before I started making posts. So, my guess is that it only affects future posts.
If anyone use a WooTheme it is very likely that you will have the same problem.
Once created, the comments_status of CPT ‘woo_’ don’t changed if you use the theme option.
The only way to get it back changing is to go in PhpMyAdmin and change value from “closed” to “open” for each post.
DTEK516 is right.
I am using WCK Custom Post Type Creator and I have set the comments checkbox on the posts and ensured via phpMyAdmin that the POSTS table shows all of them to have an open status. However, I cannot get the comments to load on the post. Any help would be appreciated as I haven’t found much online talking about comments and I believe they are supposed to work by default with the WCK plugin.
or actually you could change the source code and submit your change to the plugin developers source code within github (most of the e-commerce plugins have a github open project)
so how to find where in the plugin you should change the supports line…
on woocommerce plugin i did that, that way:
while using sublime text editor I’ve searched all the files for the occurrence of the phrase:
and that found me a couple of results but on the second result (the first find was a comment) I`ve got the code that declares new custom post type called “product”
so the string is in woocommerce/woocommerce.php file (in your plugins directory)
on line 982
so just after
add the following in the same line:
and save the file and upload to the server.
And that is it.
you’ve added to the ‘product’ custom post type declaration the option of comments in this custom post type.
<em>a couple of foot notes:</em>
your are changing the source code of the plugin.
the next time the plugin goes for an upgrade all your changes will be deleted, and you will have to do this process again from the start.
I think there is a way to re-declare the product custom post type with the new added support option, with calling this function with its attributes:
but i suggest that everybody should check that option only if they already know how to write php arrays and call functions…
- The topic ‘Enable comments on Custom Post Types’ is closed to new replies.