"comments_array" hook in functions.php has no effect in newer versions  

  RSS

Jessa Tower
(@gravityswitch)
Member Customer
Joined: 4 years ago
Posts: 5
08/07/2019 10:40 pm  

Client site is on wpDiscuz Version 5.3.2 . We need to have the order of comments for certain posts reversed, so used the following. This worked fine at one point but has broken in more recent versions of wpDiscuz. This is core WP functionality, so wpDiscuz ought to be compatible with it if possible? Note that more ordinary values for the priority parameter also did not work.

function reverse_comments( $comments , $post_id ) {
$thepost = get_post($post_id);
if ($thepost->post_type == "reviews" && $thepost->post_parent == 0) {
return array_reverse( $comments );
}
else {
return ( $comments );
}

}
add_filter( 'comments_array' , 'reverse_comments' , 99999, 2 );



Quote
Astghik
(@astghik)
Support Team Admin
Joined: 2 years ago
Posts: 3513
09/07/2019 11:04 am  

Hi Jessa Tower,

I'll ask this question to the plugin developers and let you know asap. 


ReplyQuote
Astghik
(@astghik)
Support Team Admin
Joined: 2 years ago
Posts: 3513
09/07/2019 4:38 pm  

@gravityswitch,

you cannot use the code. You should use the code you've mentioned.

You should use the wpdiscuz_comment_list_args hook, and set true value for reverse_top_level


ReplyQuote
Jessa Tower
(@gravityswitch)
Member Customer
Joined: 4 years ago
Posts: 5
10/07/2019 3:07 am  

Can you tell me why this code isn't working? The "Reverse child comments order" setting in wpDiscuz is NOT set, if that means anything. Even stripping out the conditionals I need for this particular use case, this code does absolutely nothing. I also tried a version posted on this board using array_merge rather than setting reverse_top_level directly, same result.

function set_comment_args($default_args){
$new_args = $default_args;
$new_args['reverse_top_level'] = TRUE;
return $new_args;
}
add_filter('wpdiscuz_comment_list_args', 'set_comment_args');

ReplyQuote
Astghik
(@astghik)
Support Team Admin
Joined: 2 years ago
Posts: 3513
10/07/2019 3:16 pm  

@gravityswitch

We've just checked the code above and it works fine. Please try to delete caches before checking. 


ReplyQuote
Share: