Skip Navigation

[Resolved] Allow Comments by Default for CPT

This support ticket is created 4 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by MattI4840 4 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1475965

I could just be missing it, but is there a way to allow for comments to be enabled for all posts in a cpt by default?

Thanks!

#1476077

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can activate the comments for the post created for your post type from;
=> Toolset => Post Types => Edit your post type => Under section "Sections to display when editing" => Checkmark the checkbox comments and save your post type.

Then with all of your posts belong to that post type there will be an option available "Allow Comments" when you create/edit the post for your post type.

#1476829

Hi Minesh,

Yes I'm aware of that setting, what I'm asking for is a way to ensure that every post created for that cpt has the "allow comments" box checked off by default. So for instance when I use a post form to create a new post for a cpt, I don't see a field I can add to the form to 'allow comments' unless I'm missing something. Users of the application I'm building need to be able to leave comments for some post types, but they do not have access to the dashboard.

Thanks,
Matt

#1480141

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You did not mention in your initial reply that you are using forms to create the post.

Do you mean that when user create post from frontend using the Toolset post form, you want to set comment status to open for every post - correct?

#1481311

For every post of a certain type yes, I already have a function that copies over fields from a parent post when this cpt is created, if there is a way for me to set comments to 'allow' in that function that would be perfect. I'm just not aware of syntax being that it's a cpt.

Sorry for not including all the info in my first post Minesh, I should have mentioned that it was a front end form creating the post and that I already have a corresponding function that fires using the 'cred_submit_complete' hook.

Thanks,
Matt

#1482259

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You should try to use the Toolset form's API hook: cred_save_data

You should try to add the following code to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

add_action('cred_save_data', 'func_default_open_comments_for_posttype',10,2);
function func_default_open_comments_for_posttype($post_id, $form_data) {
  // if a specific form
  $forms = array( 999,888);
  if ( in_array( $form_data['id'], $forms ) ){
    $args = array('ID' => $post_id, 'comment_status' => 'open');
    wp_update_post($args);
  }
}

Where:
- Replace 999 and 888 with your original Toolset Form IDs

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

#1485347

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.