The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Comment form for sp...
 
Share:
Notifications
Clear all

[Solved] Comment form for specific category

7 Posts
2 Users
0 Likes
3,476 Views
Posts: 17
Topic starter
(@3dwan)
Eminent Member
Joined: 4 years ago

Hello,

I was wondering how can I restrict wpdiscuz comments for certain post categories ID's, I have already made available for post type = posts & attachments but how can I make it restricted for specific post category, this is very important, I hope there is a snippet or something that would help.

Thank you

6 Replies
Alina
Posts: 71
Moderator
(@alina)
Member
Joined: 4 years ago

Hi @3dwan,

To make it work, please follow the steps below:

1. Create a custom comment form.
2. Find the "Display comment form for post IDs" option.
3. Fill the certain IDs for the posts/pages with, on where you want to display comment form, and does not fill the IDs for the posts/pages on the pages where you do not want to show the comment form.

Save delete all caches and check.

More info here: https://wpdiscuz.com/docs/wpdiscuz-documentation/getting-started/custom-comment-form/comment-form-settings/#comment_form_for_post_id

Posts: 17
Topic starter
(@3dwan)
Eminent Member
Joined: 4 years ago

My website is for users to publish posts themselves, I need wpdiscuz for these posts, but for other categories, I need the regular WP comment form. That is why, the only way to do so is by categories ID not post ID. Isn't there a snippet to restrict WpDiscuz from a few post categories?

Posts: 17
Topic starter
(@3dwan)
Eminent Member
Joined: 4 years ago

I have found this snippet in WP support forums https://wordpress.org/support/topic/1076-5000-deactivate-wpdiscuz-for-registered-members-or-for-selected-posts/

add_filter('is_load_wpdiscuz', function ($isLoad, $post) {
   if ($post->ID == X) {
      return false; 
    } 
    return $isLoad; 
}, 10,2);

I am not a developer, but since it is activated through is_load_wpdiscuz, maybe there is a way to change post ID to post category ID so WpDiscuz is excluded from all posts inside categories IDs

2 Replies
Alina
Moderator
(@alina)
Joined: 4 years ago

Member
Posts: 71

@3dwan,

Please use the following code:

add_filter("is_load_wpdiscuz", function ($load, $post) {
if (has_category([22], $post)) {
$load = false;
}
return $load;
}, 10, 2);

Please note the red marked value the category ID.

The code should be added in your active WordPress theme functions.php file.

(@3dwan)
Joined: 4 years ago

Eminent Member
Posts: 17

@alina

Great news! Thank you, and if it was meant for multiple categories, separate by commas?

Alina
Posts: 71
Moderator
(@alina)
Member
Joined: 4 years ago
Posted by: @3dwan

Thank you, and if it was meant for multiple categories, separate by commas?

Yes, this is correct.

Share: