Sauter la navigation

[Résolu] How to let the comments go to the account page automatically based on the same post author?

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

How to let the comments go to the account page automatically based on the same post author?

Solution:

It needs custom codes, for example:

https://toolset.com/forums/topic/how-to-let-the-comments-go-to-the-account-page-automatically-based-on-the-same-post-author/#post-1569007

Relevant Documentation:

This support ticket is created Il y a 5 années et 1 mois. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par FuChan Il y a 5 années et 1 mois.

Assisté par: Luo Yang.

Auteur
Publications
#1568969

Thanks for your great help. One more thing I would like to trouble you again concerning the comments.

I am trying to use Toolset Layout to create account page for different users (authors). The comments received from the posts are put in the Dashboard=>Comments together. How to let the comments go to the account page automatically based on the same post author?

Are are available shortcodes or custom codes to use? Thanks again.

#1569007

Hello,

I assume you are going to display all comments which are belongs to posts, and those post's author is same as current logged-in user.

It needs to query the comment by post author parameter, but Toolset Views does not support this feature, so it needs custom codes, for example:
1) Create a custom shortcode, add below PHP codes into your theme file functions.php:

add_shortcode('my-post-comments', function($atts, $content){
	if(!get_current_user_id()){ // guest user
		return;
	}
	$args = array(
		'post_author' => get_current_user_id(), // It will use the current logged in use to grab the comments
	);
	$comments = get_comments( $args );

	// Referer to http://codex.wordpress.org/Function_Reference/wp_list_comments
	$list_args = array(
		'reverse_top_level' => false, // Show the latest comments at the top of the list
		'echo' => false,
	);
	$res = wp_list_comments( $list_args, $comments );
	return $res;
});

2) Display above shortcode like this:
[my-post-comments]

#1569723

My issue is resolved now. Thank you!