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

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

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

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


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


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

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

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


2

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


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

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

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

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

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.


1

As far as I remember awaiting moderation message should be only visible to author of the comment. If it is displaying otherwise it might be faulty caching implementation or other code interfering. The customization of it depends on where it is coming from - it can be WP core, core theme or third party theme using same string.


1

Try get_comment_pages_count()? <?php get_comment_pages_count( $comments, $per_page, $threaded); ?> I'm guessing you're outside the loop, since you're calling get_comments(); in that case, you'll need to pass your $comments object: $comments = get_comments(array( 'post_id' => $post_id, 'status' => 'approve' )); ...


1

The default for reverse_top_level is null. Now let's take a look at the function source: if ( null === $r['reverse_top_level'] ) $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ); As you can see, it takes the value from the comment_order option. And that is either desc or asc. If the value is desc, then it will be set to true. Now ...


1

What you need to do to achieve this is to provide the second parameter of wp_list_comments(), which would be $comments and is described like this: (array) (optional) Array obtained by get_comments query. Default: The default return of get_comments. Which actually makes it clear what you need to do, which would be utilizing get_comments(). Below ...


1

Generally comments are being displayed using comments.php, the template is rendered using a function called comments_template();. If- there is a comment template in your theme and it contains a function called comment_form(), and the comment template is being displayed below the post (in single.php, page.php etc.), and your comment settings from the Admin ...


1

You get the comment_karma property because there is such a column in the comments table. It is meaningless and AFAIK was never used for anything except for maybe some random spam prevention plugin. It is there just for backward compatibility and because no one thinks that removing it will improve anything in a measurable way. You can use that field if ...


1

You could try to add your own custom get_comment_link filter just before you call the wp_list_comments() function: // Modify comment links add_filter( 'get_comment_link', 'wpse_comment_link', 10, 4 ); // Display comments wp_list_comments( $args, $comments); where our callback is defined as: function wpse_comment_link( $link, $comment, $args, $cpage ) { ...


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

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

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


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

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


1

use the "parent" parameter as 0. $args = array( 'parent'=>0 'post_type' => 'custom-post-type', 'number' => '1', 'orderby' => 'date', 'order' => 'DESC' ); $comments = get_comments($args); foreach($comments as $comment) : echo($comment->comment_author . '<br />' . $comment->comment_content); ...



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