Puede tener varios autores escribiendo contenidos en su blog. Cada entrada del blog tiene una sección de comentarios donde los usuarios pueden dejar un comentario después de leer la entrada. Normalmente, todos los comentarios son visibles para todo el mundo con los permisos para verlos en su área de administración de WordPress.
Instrucciones: Para mostrar los comentarios a las propias entradas de los autores y ocultar los demás comentarios, puedes añadir el siguiente código al archivo functions.php de tu tema de WordPress.
function wps_get_comment_list_by_user($clauses) { if (is_admin()) { global $user_ID, $wpdb; $clauses['join'] = ", ".$wpdb->base_prefix."posts"; $clauses['where'] .= " AND ".$wpdb->base_prefix."posts.post_author = ".$user_ID." AND ".$wpdb->base_prefix."comments.comment_post_ID = ".$wpdb->base_prefix."posts.ID"; }; return $clauses; }; if(!current_user_can('edit_others_posts')) { add_filter('comments_clauses', 'wps_get_comment_list_by_user'); }
También puedes disfrutar añadiendo la autoría de Google a WordPress.
Any way this can used for frontend comments only?
Hello! Thank you so much for this code! It worked beautifully on my site, except for one thing: I am using multiple authors plugin and it doesn’t filter for the co-authors. Can you help me?
How are you designating co-authors? For example, are you using user roles?
Thank you for your answer. I am using the Co-Authors Plus plugin. It adds a custom field where you can add as many authors as you want.
Hello, this worked nicely. But is there any way to hide total comment count/approved/trash too? All the numbers should only show figures by the author.
Great solution. Today solve my problem . Thank you so much.
Glad it helped 🙂
Hello, In admin the count of comments still show all comments not filtered comments.
Hi Kevin,
Thank you for your great efforts and support!
I am wondering if I can as Administrator write a comment and make it visible JUST for specific user or user role (author, editor…etc.). Comments are disable normally and no one can write one.
I am looking forward to your answer!
Thank you from Vienna,
Alexander Edelmann
please help me
you are explain how show the comments to the authors own posts
, I want filter the notify of comments for owner post ? how
You made my day! Thank you so much @wpsnipp:disqus for this valuable tutorial.
It would be great if we could fix comment counts for contributor profile. Thanks
work in localhost but don’t work in host ???
If the database preifx is something else than wp_ this function won’t work. You should replace wp_ by “.$wpdb->base_prefix.” in join and where clause to fix it.
I meant database prefix
For the life of me I cannot make this work with a different db prefix (my website’s is wp_spanh) I am not at all php literate, so could you please give me the above function with my db prefix in place, so that I can copy / paste it into my functions.php file? I would be eternally grateful!
For the life of me I cannot make this work with a different db prefix (my website’s is wp_spanh) I am not at all php literate, so could you please give me the above function with my db prefix in place, so that I can copy / paste it into my functions.php file? I would be eternally grateful!
Hi Ismael
I just updated the snippet to work with any prefix should work fine I tested things on the most recent version of wordpress.
[…] for this useful snippet goes to Kevin Chard of […]
Where do I copy this code ?
Sorry about that, I update the post. Just add this snippet to the functions.php of your wordpress theme.
But, On pasting the code in theme’s folder/functions.php, the whole comment is disappeared. No comments is visible now. Even, the logged in user’s.
Hey, thanks for your amazing site!
No problem enjoy the wordpress code snippets
Ah! 🙂 Thanks .. another great snippet! Very much similar to author post restriction!
I’m loving your site!!! 🙂
Glad to hear it, lots of stuff on the way 🙂
This is pretty cool, thanks for sharing.
No problem Andrew,