Hot answers tagged

6

Yes, it is possible, but it is a bit of a pain. Looking at the codex page, only arguments of note are number and offset. We need these two to create our paginated pages. First, we set the $paged parameter, which is the current page: $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; Then number of comments to display: $number = 3; ...


5

I was curious about any existing plugins and searched the plugin directory. There exists an old Sticky Comments plugin, I'm not related to it. It seems to use a sticky meta key. It uses a LEFT JOIN query but creates it's own version of the whole comments_template() core function, to override the current query. One would need to update that custom function, ...


5

Note that the function wp_list_comments() doesn't fetch the comments, only displays them in various ways depending on the input arguments. You're actually using the WP_Comment_Query/get_comments input arguments into wp_list_comments(). You could try this instead: $postID = 12345; // Adjust this! $comments = get_comments( [ 'date_query' => ...


4

What you need to use here is the WP_Comment_Query() function. So on the author.php page, you can easily get the author info and ID as followed: // get author info $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author)); // set ID $user_id = $curauth->ID; Then we add the user ID in the query ...


4

It's not a bug (gasp!) really just not provided for. You have to add a filter to do this, eg add_filter( 'comments_clauses', function ( $pieces, $query ) { if ( empty( $query->query_vars['wpse_no_password'] ) ) return $pieces; global $wpdb; $pieces[ 'where' ] .= $wpdb->prepare( ' AND ' . $wpdb->posts . '.post_password = %s', '' ); ...


4

From WordPress Version 4.1 (trac ticket #20446) it's now added to pass your own class as an argument of comment_form($args) using 'class_submit' array key: $args = array( 'class_submit' => 'btn btn-default' ); No need to do extra hard work. (Edited the Codex too) :)


4

Refrain from editing core files WordPress was developed with extensibility in mind, and provides many ways to change the appearance and functionality of an installation without altering the WordPress software itself (mostly using Hooks in conjunction with Plugins and Themes). The software is comprised of it's "core files", which are generally ...


3

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" ...


3

There is no "safe" way to edit core files; if you do you will need to check and repeat the edition after every update. Not recommended at all. Instead of editing core files, you could use any of the actions and filters available. For example, pre_comment_on_post (example code not tested): add_action( 'pre_comment_on_post', function( $post_id ) { if( ...


3

is_page() is not available at that point try using global $post that way the post ID should be available for comparison. add_filter( 'preprocess_comment', 'wpb_preprocess_comment' ); function wpb_preprocess_comment($comment) { global $post; if ((strlen( $comment['comment_content'] ) < 60 ) && ($post->ID == 42)) { wp_die('Minimum allowed ...


3

The alternative way to handle this problem is to use paginate_links() with get_comments() (or any similar query). Specifically to get the equivalent of max_num_pages, you can use the built-in function wp_count_comments(). So, to get your maximum number of pages, you'd first produce a count of all the comments you want. Presuming you don't want unapproved ...


3

For flexibility, you could assign the CSS bubblecount class to the corresponding menu item: and then target it with: if( in_array( 'bubblecount', (array) $item->classes ) ) $output .= '<span class="unread">'.my_function_here().'</span>'; in your code snippet above.


3

You won't get a comment ID until the post is is inserted into the database. Before that point, the ID doesn't exist. You have to use a hook that fires after that event... 1735 /** 1736 * Fires immediately after a comment is inserted into the database. 1737 * 1738 * @since 1.2.0 1739 * 1740 ...


3

WordPres will not allow you, using its default comment process, to insert empty comments into the database. This is enforced by wp_handle_comment_submission() with the following unconditional code: if ( '' == $comment_content ) { return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 200 ); } ...


3

If you need to modify the max depth, you could use the thread_comments_depth_max filter: /** * Set max comments depth to 15 on the discussion settings page */ add_filter( 'thread_comments_depth_max', function( $max ) { return 15; } ); then the dropdown on the discussion settings page will show the range 1 - 15. But I can imagine very deep comment ...


3

Lets try the following: By default, all posts are returned regardless of comment_status, so lets run the main query as normal, that is, query all posts regardless of comment_status. We will also run a small, but very lean secondary query where we will get all posts which have a comment_status of closed which have a meta value of not yes The returned ...


3

We could rewrite: wp_list_comments( array( 'callback' => 'bootstrap_comment_callback', )); with the null walker parameter: wp_list_comments( array( 'walker' => null, 'callback' => 'bootstrap_comment_callback', )); which means we are using the default Walker_Comment class: wp_list_comments( array( 'walker' ...


2

Here are some options on how we can override the native layout for each comment: Approach #1 - Overriding start_el() with a custom walker Let's define our custom wpse comment format: // Arguments for wp_list_comments() $args = [ 'style' => 'ol', 'format' => 'html5', 'short_ping' => true, ]; // Use our custom walker if ...


2

Here are three different methods to modify the trash count, to 999 as an example: Method #1 The views_edit-comments filter: add_filter( 'views_edit-comments', function( $views ) { $trash_count = 999; // <-- Adjust this count // Override the 'trash' link: $views['trash'] = sprintf( "<a href=%s>%s <span ...


2

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' ) ...


2

You probably can hack comments in somehow, but don't. Create a custom post type for your musicians using register_post_type() and including "comments" support. You can then create post type templates to customize the display: archive-{post_type}.php -- for archives single-{post_type}.php -- and for single posts ...


2

Note that with the following: add_filter ('comments_template', 'fbcommentbox', 100); we expect fbcommentbox() to return the path to the new comments template file. The default is the path of comments.php. If you create the fbcommentbox.php file in your theme, then you could try: add_filter( 'comments_template', 'fbcommentbox', 100); function ...


2

You can pass the number argument to get_comments() to retrieve only a specific number of comments. They will, by standard, be sorted descending, so you get the latest comments first. As WordPress automatically seperates comments for each post, you will not have to worry about mixing comments up. This seems to be the easiest way for me. Multiple comment ...


2

Finally I figured it out. you may simply add your arguments to the wp_list_comments as associative key => value pairs like this: $args = array( 'callback' => 'my_callback', 'avatar_size' => 48, 'type' => 'comment', 'arg1' => $arg1 ); wp_list_comments( $args ); and then in your my_callback you have: function my_callback( $comment, $args, ...


2

Add following code in your theme's functions.php. // To add extra column in column headers add_filter('manage_posts_columns', 'bs_event_table_head'); function bs_event_table_head( $defaults ) { $defaults['pending_comments'] = 'Pending Comments'; return $defaults; } // To add data in column for each post. add_action( 'manage_posts_custom_column', ...


2

Note that it might be easier to use get_comments() here, since it's defined as: function get_comments( $args = '' ) { $query = new WP_Comment_Query; return $query->query( $args ); } If you need the comment url, within your foreach comment loop, you can use: $comment_url = esc_url( get_comment_link( $comment ) ); You can also get the post id ...


2

You're re-inventing the wheel here ;-) The Problem You're bypassing WordPress with this approach, so that's explains the error message. Accessing any custom file, within your theme directory, will not load WordPress core automatically. Already available This is already supported by the WordPress core. You should check out comments_popup_link() and ...


2

Those options do not appear from the core but, they're are part of the Jetpack plugin. You should check with Jetpack files. Off-topic: I personally would prefer to disable these on Woocommerce pages. Hope this helps


2

Bulk edit the existing pages in the dashboard Posts or Pages view as noted here: Go to your All Posts page. Click on the checkbox in the header. Choose "Edit" under the bulk actions drop-down and then click Apply. The bulk edit area will appear. In the middle of the bulk edit area will be four drop-down menus. The second one is for comments. Change it to ...


2

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 ...



Only top voted, non community-wiki answers of a minimum length are eligible