Hot answers tagged

5

You'll need to filter comments_clauses, since WP_Comment_Query only supports a limited post type == X argument. /** * Exclude comments of the "foobar" post type. * * @param array $clauses * @param object $wp_comment_query * @return array */ function wpse_72210_comments_exclude_post_type( $clauses, $wp_comment_query ) { global $wpdb; if ( ! ...


4

The pre_get_comments hook Note that the single post's comments are fetched with get_comments(), within the comment_template() function. The get_comments() function is just a WP_Comment_Query object wrapper, so we can restrict the comment query with the pre_get_comments hook. Example #1 Here's a simple user_id restriction example: ! is_admin() && ...


3

There is no argument to restrict a comment query directly to a given date. You have to filter the query later: /** * Get the number of comments for a post today. * * @param int $post_id * @return int */ function t5_count_comments_today( $post_id = NULL ) { if ( NULL === $post_id ) $post_id = get_the_ID(); add_filter( 'comments_clauses'...


3

The first you do: separate regular comments and pingbacks. In your comments.php set the type parameter for both: <ol class="commentlist"> <?php // show regular comments wp_list_comments( array ( 'type' => 'comment', 'style' => 'ul' ) ); ?></ol> <ol class="pinglist"> <?php // show pingbacks and ...


3

Check the Codex for wp_list_comments. Scroll down to the part labeled "Source File", which is there on almost every Codex entry. Click the accompanying link. And there you are. Sometimes (usually) the line number in the Codex entry is wrong though. Now you can happily go about hacking Core files and causing yourself no end of pain and heartache. If you ...


3

You should place your code inside the loop and add to the args array 'post_id' => get_the_ID() so it should look like this: while(have_posts()){ the_post(); //your post loop output $args = array( 'status' => 'approved', 'number' => '5', 'post_id' => get_the_ID() ); $comments = get_comments($args); foreach($...


3

Hi Just need to make your function to get comments and then use your function output at required places. <?php get_comments( $args ); ?> <?php $args = array( 'user_id' => $author_id_to_limit, ); get_comments( $args ); ?> Set Number to your variable like I did in above code. Rest of args please put accordingly. For details follow this ...


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


3

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


2

Most likely, the main thing that you missed is that you must have "Break comments into pages" checked in the Settings Discussion Subpanel. The pagination functions require this to be set, as do the URL rewrites. Here's a working, complete page template to do what you're asking: <?php /* Template Name: All Comments See http://wordpress.stackexchange.com/...


2

The issue with trying to subvert whole database access is that even on page, dealing with comments, WP will still need and perform queries for other data. The challenge is not as much changing where query go, as changing it without everything falling apart. Your best chance it probably to try some solution for sharding on WP level (such as HyperDB or SQL ...


2

You can filter query. See wpdb::query() in wp-includes/wp-db.php. You get the complete SQL string as parameter. Then look for queries to the comments table: add_filter( 'query', function( $query ) { global $wpdb; if ( FALSE === stripos( $query, "FROM $wpdb->comments" ) return $query; // Now change the SQL }); But you have to ...


2

Just add the comments to oEmbed. Here's a small plugin that you can use as MU-Plugin or normal plugin and that should explain what's going on pretty well. <?php defined( 'ABSPATH' ) or exit; /* Plugin Name: (#105942) oEmbed Comments */ add_filter( 'comment_text', 'wpse_105942_oembed_comments', 0 ); function wpse_105942_oembed_comments( $comment ) { ...


2

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


2

This is going to be a labor intensive workaround but get_comments is probably what you want. From the Codex: $comments = get_comments('post_id=15'); foreach($comments as $comment) : echo($comment->comment_author); endforeach; There is also WP_Comment_Query if you prefer.


2

So apparently this is a big no-go, but I've been able to build my own custom comments form and loop using this code: <?php $args = array( 'post_id' => $post_ID); $comments = get_comments($args); if($comments) : foreach($comments as $comment) :?> <div class="comment"><?php print_r($comment); ?></div> <?...


2

In the default usage this is impossible due to the nature of the default comment walker which always directly outputs. But the function allows to provide a custom walker. Further reading about custom walkers: Codex Class reference example custom walker class You could also use output buffering to save it into a variable (this is considered to be dirty): ...


2

I realized that comment-reply.js is not loaded and it fixed the issue. Could someone explain? I have no idea what happened. So the fix was adding wp_enqueue_script( 'comment-reply' ); to my plugin code.


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


1

Use get_comments function.Pass Post_id as parameter.See below example <?php $comments = get_comments('post_id=15'); foreach($comments as $comment) : echo($comment->comment_author); endforeach; ?> for more detail please check below link http://codex.wordpress.org/Function_Reference/get_comments


1

The third parameter of wp_register_script is $deps-- dependencies. wp_enqueue_script also accepts a $deps parameter, by the way. wp_register_script( $handle, $src, $deps, $ver, $in_footer ); $deps is an array of scripts upon which the script being registered depends. Dependencies load before the scripts upon which they depend. WordPress will juggle things ...


1

In your functions.php: edit: First register the quicktags script under a different name than already registered in wp "quicktags" , see Codex function quicktags_script() { wp_register_script( 'quicktags-min', '/wp-includes/js/quicktags.min.js?ver=3.5.1','','',true); wp_enqueue_script( 'quicktags-min' ); } add_action( 'wp_enqueue_scripts', '...


1

Add style=ol to your call to wp_list_comments. Reference: http://codex.wordpress.org/Function_Reference/wp_list_comments#Parameters


1

ok.. so I did it like this. Maybe will help some. Used the code from Last comment page first with full number of comments? but altered it a bit to fit my needs. So this goes into your template page where you call the comments (or you can wrap it in a function and put it into functions.php) <?php comments_template( '', true ); ?> <?php $...


1

The database table that WordPress uses to store its comments has a couple date fields in it -- comment_date and comment_date_gmt. You should be able to do something like this: function wpse99287_comment_count( $content ) { global $wpdb; global $post; $today = date( 'Y-m-d 00:00:00' ); $tomorrow = date( 'Y-m-d 23:59:59' ); $sql = "SELECT ...


1

This function replaces the comment author's link with the comment author's profile page, if the comment author is a registered user. Otherwise, the standard WordPress comment author link is displayed. This function is not mine and has been found googling. function graphene_comment_author_profile_link(){ /* Get the comment author information */ ...


1

To fix the numbering, you'll have to modify the first code to reset numbering via CSS. This way (untested, but you'll catch the idea ;) ). <?php if ( have_comments() ) : ?> <h3 class="com"><span class="com-titlu"><?php comments_number('Niciun comentariu', 'Un comentariu', '% comentarii' );?></span> la: <?php the_title(); ...


1

I am using a helper function for that. functions.php /** * Count amount of pingbacks + trackbacks for a post. * * @param int $post_id Post ID for comment query. Default is current post. * @return int */ function t5_count_pings( $post_id = NULL ) { $pings = 0; $comments = FALSE; if ( NULL !== $post_id ) { $comments = ...


1

Well, I have the solution. first, use the global variable $comment_depth, pass it to twentyeleven_comment() function, and in the twentyeleven_comment() function, define a new variable named $defaults like this: function twentyeleven_comment( $comment, $args, $depth ) { $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', '...


1

you can use the widget_comments_args filter to modify the default args of the recent comments widget: function wpse80087_widget_comments_args( $args ) { $args = array( 'number' => 5, 'post_type' => 'attachment', 'status' => 'approve', 'post_status' => 'inherit' ); return $args; } add_filter( 'widget_comments_args', '...



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