Tag Info

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


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


2

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


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

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

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

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.


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

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

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


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

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


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


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

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

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

Note - It uses the values stored in global variable - wp_query. Usually the wp_query variable contains comments of current post when browsing. Usage - $comments = wpse61072_hide_admin_comment(5); // 5=max comments foreach ( $comments as $comment ) { echo '<li>'.$comment->comment_author.' - said : ...


1

Totally untested, but you should be able to use the pre_get_comments filter: function exclude_admin_comments($query) { $query->query_vars['user_id'] != 1; } add_action('pre_get_comments', 'exclude_admin_comments');


1

Yay! We got filters! Wrapping the result of the $wpdb comments query right into a filter callback (and a plugin) is the nice way of handling comments. /* Plugin Name: Ā»KaisersĀ« Comments without admin comments */ ! defined( 'ABSPATH' ) AND exit; add_filter( 'comments_array', 'wpse_61072_comments_without_admin', 20, 2 ); function ...


1

Just build a link that has some query args: printf( '<a href="http://example.com/all-comments?pid=%s">All comments</a>' ,get_the_ID() ); Then add a page with a a permalink of all-comments, so you have something to target. There you attach a template like the following (just a base to work off): <?php /** * Template Name: All ...


1

to remove it from the left. Delete the line containing wp_list_comments from comments.php to display user name add comment_author();, for email use comment_author_email(); & for url use if(get_comment_author_url()) comment_author_url();. comment_text() is already there. These all go in the markup inside the function in functions.php



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