Count all comments of a custom post type

How about direct sql with a simple subquery to first get all the post ids of your custom post type ex: function get_all_comments_of_post_type($post_type){ global $wpdb; $cc = $wpdb->get_var(“SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID in ( SELECT ID FROM $wpdb->posts WHERE post_type=”$post_type” AND post_status=”publish”) AND comment_approved = ‘1’ “); return $cc; } Usage: $total_comments = get_all_comments_of_post_type(‘some_post_type’);

When trashing a post, also trash related comments

Well, this is partly true and partly false. When you trash a post, everything that is tied to it is also trashed. This means, if you untrash the post, the comments etc. are untrashed as well. However, comments and other stuff is not handled as if they were trashed directly (i.e., on the Comments page … Read more

Add classname comment template from functions.php

You should consider hooking into the comment_class() and post_class() filters, if your theme supports it. Using the comment_class filter: We can add the following filter: /** * Add a custom comment class, based on a given comment author’s user meta field. * * @see http://wordpress.stackexchange.com/a/170443/26350 */ add_filter( ‘comment_class’, function( $classes, $class, $comment_id, $post_id ) { … Read more

Change username to nickname in comment section

Yes, of course it won’t show any name for guest comments because they are not registered users of your website so they don’t have any nickname associated. What you can do in this situation, is add a check before printing the nickname, if comment was made by a user or a guest. And act accordingly. … Read more

Comment form connection to Gravity Forms

This is possible using the comment_post action, and the GFAPI class which handles entries in WordPress. What you need to first is add using comment_form_default_fields a field which is a checkbox. function add_to_email_list_field($fields) { $fields[‘add-to-email’] = ‘<p class=”comment-form-public”> <input id=”addtoemail” name=”addtoemail” type=”checkbox” /> <label for=”addtoemail”> Check this box to add yourself to our email list. … Read more

How to add replyToUrl schema.org to WordPress comments?

You could instead try the following replacement: /** * Add itemprop attribute to the comment reply link */ add_filter(‘comment_reply_link’, function( $html ) { if( false === stripos( $html, ‘itemprop=”‘ ) ) $html = str_ireplace( ‘<a ‘, ‘<a itemprop=”replyToUrl” ‘, $html ); return $html; }, 99 ); through the comment_reply_link filter. The HTML generation, of the … Read more

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