Get a variable field of all comments of current post

To get the comments use get_comments() and the current post’s ID. To get the URL fields only use wp_list_pluck(). To remove the empty fields use array_filter() without a callback. . $comment_urls = array (); $all_comments = get_comments( array ( ‘post_id’ => get_the_ID() ) ); if ( $all_comments ) { $comment_urls = array_filter( wp_list_pluck( $all_comments, ‘comment_author_url’ … Read more

where to modify get_comment_author_link()?

You would have to use the get_comment_author_link filter for this in the following manner. add_filter( “get_comment_author_link”, “wpse_63316_modifiy_comment_author_anchor” ); function wpse_63316_modifiy_comment_author_anchor( $author_link ){ return str_replace( “<a”, “<a target=”_blank””, $author_link ); }

Prevent Contributor to show comment list

Paste this code inside the functions.php file of your currently active theme. You can make it a plugin file too. It uses the “the_comments” filter to remove the unwanted comments from the backend table. /** * Filter out comments of other posts than current logged-in user. * * @param $all_comments all the comments to be … Read more

What should I hook to add extra fields to comments?

First you have to add your input fields to comment form. You can use these two hooks for that: comment_form_logged_in_after comment_form_after_fields Here’s how: function add_my_custom_field_to_comment_form() { ?> <p class=”comment-form-<FIELD_ID>”> <label for=”<FIELD_ID>”><?php _e( ‘Your <SOMETHING>’, ‘<TEXTDOMAIN>’ ); ?><span class=”required”>*</span>:</label> <input id=”<FIELD_ID>” name=”<FIELD_ID>” value=”” placeholder=”” /> </p> <?php } add_action( ‘comment_form_logged_in_after’, ‘add_my_custom_field_to_comment_form’ ); add_action( ‘comment_form_after_fields’, ‘add_my_custom_field_to_comment_form’ ); … Read more

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

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

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

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