Notifications
Clear all

Limited Support

Our team is currently on holiday, so support will be limited during this period. Response times may be slower than usual, and some inquiries may be delayed. We appreciate your patience and understanding, and we’ll resume our usual support by the end of August.

 

[Solved] "Recent Comments" Display Specific Custom Post Type Only?

9 Posts
2 Users
2 Reactions
1,481 Views
Curtis
Posts: 60
Customer
Topic starter
(@cbisel16)
Member
Joined: 9 years ago

I'm trying to display a list of recent comments from my course lesson custom post type on my membership website. I allow members to post comments under each lesson. 

But, when I go to my Addon widget "wpDiscuz Widgets" to display "Recent Comments" from my course lessons, the widget also confusingly displays recent comments from my blog posts as well, where I also have wpDiscuz setup to allow comments. There doesn't seem to be a pulldown menu option in this paid widget to allow me to choose which post type I want to pull from.

Is there a way to make this work?

8 Replies
Astghik
Posts: 6444
Admin
(@astgh)
Illustrious Member
Joined: 8 years ago

Hi,

We're going to adda new hook in the next version of the addon. So once the new version is ready you'll be able to filter the widget.

7 Replies
Curtis
Customer
(@cbisel16)
Joined: 9 years ago

Member
Posts: 60

@astgh 

Oh, great — thank you! I will keep an eye out for the next version.

Astghik
Admin
(@astgh)
Joined: 8 years ago

Illustrious Member
Posts: 6444

@cbisel16,

I'll update this topic once the new version is ready.

Curtis
Customer
(@cbisel16)
Joined: 9 years ago

Member
Posts: 60

@astgh ~ am I correct in that this plugin was just updated? If so, can you share how I can make this work now?

7.2.5

  1. Added: New hooks to manage comments/posts args in tabs

 

Astghik
Admin
(@astgh)
Joined: 8 years ago

Illustrious Member
Posts: 6444

@cbisel16,

The following hooks are added: 

  • apply_filters("wpdiscuz_widget_most_active_comments_threads_args", $all_comms_args); 
  • apply_filters("wpdiscuz_widget_most_voted_comments_args", $all_comms_args);  
  • apply_filters("wpdiscuz_widget_recent_comments_args", $args);  
  • apply_filters("wpdiscuz_widget_top_rated_posts_args", $all_posts_args);

This article should be helpful for you:

https://developer.wordpress.org/reference/functions/get_comments/

Curtis
Customer
(@cbisel16)
Joined: 9 years ago

Member
Posts: 60

@astgh 

I'm sorry to be a pest, but I guess I'm considered a non-coder here (just an above-average end-user). I checked out this article you mentioned, but the examples don't seem to be complete in a way that I feel confident I can reverse engineer one to fit my needs. 

Would it be possible for you (or someone else on the team) to share an example code I can paste into my "Code Snippets" plugin to filter out the "post" CPT and just show my CPT "Lessons" (as "Recent Comments") using this hook you said was just added?

I am guessing it looks something like this below (with the help of ChatGPT), but as it's currently written, isn't working for me when I paste it in and activate it (it's still showing "Post" post type comments as well):

// Add a filter callback function
function custom_filter_recent_comments_args($args) {
    // Check if the comments widget is being displayed
    if (is_active_widget(false, false, 'wpdiscuz_recent_comments_widget', true)) {
        // Modify the arguments to include your custom post type "Lessons" and exclude default post type
        $args['post_type'] = array('lessons');
    }

    return $args;
}

// Hook the filter function to the wpdiscuz_widget_recent_comments_args hook
add_filter('wpdiscuz_widget_recent_comments_args', 'custom_filter_recent_comments_args');
Astghik
Admin
(@astgh)
Joined: 8 years ago

Illustrious Member
Posts: 6444

@cbisel16,

Please use this code: 

// Add a filter callback function
function custom_filter_recent_comments_args( $args ) {
	// Modify the arguments to include your custom post type "Lessons" and exclude default post type
	$args['post_type'] = array( 'page' );

	return $args;
}

// Hook the filter function to the wpdiscuz_widget_recent_comments_args hook
add_filter( 'wpdiscuz_widget_recent_comments_args', 'custom_filter_recent_comments_args', 1 );
Curtis
Customer
(@cbisel16)
Joined: 9 years ago

Member
Posts: 60

@astgh ~

Once I changed 'page' to my CPT 'lessons', your code worked perfectly. Thank you!!! 

Share:
Scroll to top