Show only posts which can be commented

Because comment_status is not a built-in query argument – but you can easily implement it: function wpse_214323_query_by_comment_status( $where, $wp_query ) { global $wpdb; if ( ! empty( $wp_query->query_vars[‘comment_status’] ) ) { $status = $wp_query->query_vars[‘comment_status’]; if ( $status !== ‘open’ ) $status=”closed”; $where .= ” AND $wpdb->posts.comment_status=”$status””; } return $where; } add_filter( ‘posts_where’, ‘wpse_214323_query_by_comment_status’, 10, 2 … Read more

Customize comment list markup

You should use wp_list_comments(), because this will call a Walker class that can handle comment threads: // from wp_list_comments() if ( empty($walker) ) $walker = new Walker_Comment; $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r); Walker_Comment handles the markup for the comments. You can pass a custom walker to change it. Example: class Simple_Comment_Walker extends Walker_Comment { function … Read more

Add a drop down list to comment form?

Filter comment_form_field_comment to add a select element with a label. Add a callback to the action comment_post to save the value. Filter comment_text to show the value for a comment. Sample code: add_filter( ‘comment_form_field_comment’, function( $field ) { global $wp_roles; $user = wp_get_current_user(); $select=”<p><label for=”roleselect”>Your role:</label> <select name=”prefix_role” id=”roleselect”> <option value=””>Select a role</option>”; foreach ( … Read more

Use comments as notes, visible for comment author only

I used _s as a template. The comments are loaded with wp_list_comments( array( ‘callback’ => ‘_s_comment’ ) ); and then comments are styled with _s_comment(). That is what you will use. You can use get_current_user_id() to get the current user id. $current_user_id = get_current_user_id(); You can get the user id of the commenter with $comment->user_id. … Read more

Upload images with comment

EDIT: With some help of a friend I came up with a solution. For everyone interested: Use a custom post-type, in my case comment_post. Then upload the images like this: $new_post = array( ‘post_title’ => $title, ‘post_content’ => $comment, ‘post_status’ => ‘pending’,// Choose: publish, preview, future, draft, etc. ‘post_type’ => ‘comments_post’ // Use a custom … Read more

Get Comments: Direct link to specific comment + post title

Instead of $comment->post_ID use $comment->comment_post_ID. Your code will look like following: <?php $comments = get_comments(‘status=approve&number=5′); ?> <ul id=”recent_comments”> <?php foreach ($comments as $comment) { ?> <li><p><strong><?php $title = get_the_title($comment->comment_post_ID); echo get_avatar( $comment, ’45’ ); echo strip_tags($comment->comment_author); ?></strong>&nbsp;commented on <a href=”https://wordpress.stackexchange.com/questions/28690/<?php echo get_permalink($comment->comment_post_ID); ?>” rel=”external nofollow” title=”<?php echo $title; ?>”> <?php echo $title; ?></a>: <?php echo … Read more

How to enable visual editor when editing comments on the dashboard?

If you are using WordPress 4.0+ you can do this using the wp_editor_settings and the global $pagenow to determine if you are on the comments page. add_filter( ‘wp_editor_settings’, ‘remove_editor_quicktags’, 10, 2 ); function remove_editor_quicktags( $settings, $id ){ global $pagenow; if ( $id == ‘content’ && $pagenow === ‘comment.php’ ){ $settings[‘quicktags’] = false; $settings[‘tinymce’] = true; … Read more

Custom comment type maybe?

I also (ab?)use comments for “private” replies to posts, like product inquiries, suggestions, answers to contests, … The advantage is that they are stored in the database and displayed in the interface without extra code from me (sometimes I add a filter to improve the formatting). Spam filtering and e-mail notifications are easy extras. I … Read more

Can’t get ID of post that relates to the comment

comment_post hook pass to attached functions 3 parameters. The fourth parameter of add_action() indicates to how many parameters the attached function will be able to access. add_action( ‘comment_post’, ‘save_chbox_in_db’, 10, 3 ); function save_chbox_in_db( $comment_ID, $comment_approved, $commentdata ) { $post_id = (int)$commentdata[‘comment_post_ID’]; // // other code // }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)