For example post has comment area with 3 differnet tabs, e.g comments, reviews and questions.
I've looked into it for some time know but I haven't came up with a perfect plan.. I figured it's time to address WordPress gods here.
Concept is easy:
------------------------------------------------------------------
1. category link 2. category link 3. category link
------------------------------------------------------------------
Current category comments
------------------------------------------------------------------
If one of the links is clicked, run (via ajax or not, matter of taste) query that get X category comments.
I've looked into WP_Comment_Query() but Im not sure how to handle this.. There's no category or type parameter, so I figured that comment meta is probably the best way to go..
Adding category when commenting:
//To functions.php or create a plugin
add_action( 'comment_post', 'add_comment_category' );
function add_comment_category( $comment_id ) {
add_comment_meta(
$comment_id,
'my_comment_category',
$_POST['hidden-input-category-value']
);
}
- Front-end is pretty much covered but admin area is whole different story and Im not sure that I should add hidden input to everywhere you can comment (edit post page, comments page etc). Is there a better alternative to that? How else could I pass current category value?
- Also hidden input can be altered by mean people and break the system - not good at all.
- Im pretty sure that I should do commenting via ajax so that I wouldn't have to worry about opening wrong tab when page reloads.
Admin area output:
I don't need to sort them by categories in admin area, I'll just add new column to comments list that outputs the category just in case, maybe there will be times when I need to know.
Front-end output:
//Create new template for this comment system and use get_template_part()
//Or add it straight to post or page template
$args = array(
'post_id' => $current_post_id,
'meta_query' => array(
array(
'key' => 'my_comment_category',
'value' => 'review'
)
)
);
$comments = new WP_Comment_Query( $args );
//Output
while( $comments->have_comments() ) {
$comments->the_comment();
//Output
}
else {
//No comments output
}
This is inspired by my usual WP_Query()
build. I imagine there's consistency in WordPress and all different query results can be looped the same way and used rather similar code ( e.g the_post() == the_comment() or have_posts() == have_comments()
).
- Im not sure if replying works by default
- Im not sure if nested comments work by default
- Im not sure if there are any other poblems that I don't see at the moment
I guess the right question now is: Is it worth it? Would it perform much worse than default comments? Any alternatives?
Any more questions or ideas? Good, let me know and I'll update the question.
comment_type
), you could look into that for implementation ideas. Update: searched and found e.g. this thread on this site.