Load comments.php template outside the post loop

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> <?php endforeach; endif;?>

How can I get a list of comments by target

When it comes to retrieve posts, it’s supposed to call WP_Query. WP_Query has an argument called meta_query but it doesn’t have comment_query. So it might need a trick to achieve what you want, $args = array(); $args[‘feed’] = 1; $args[‘withcomments’] = 1; $args[‘author’] = 1; //author id. $query = new WP_Query($args); $posts = $query->posts; //do … Read more

oEmbed does not work for comments

You can use the oEmbed in Comments plugin. This is the code the author, Evan Solomon, uses in this plugin, I used it on a site a while back just copy it in your themes functions file or even better, download his plugin ๐Ÿ™‚ class ES_oEmbed_Comments { function __construct() { add_action( ‘init’, array( $this, ‘init’ … Read more

Redirect to page 2 after comment

After reading a bit on regex and preg, starting from a previous example of a similar problem and testing it I was able to answer my own question. I added this function to functions.php: <?php /** Plugin Name: WPSE (#167237) Redirect after comment */ add_filter(‘comment_post_redirect’, ‘redirect_after_comment’); function redirect_after_comment($location) { return preg_replace(“/comment-page-([\d]+)\/#comment-([\d]+)/”, “2”, $location); } It’s … Read more

Get a List of All Commenters on the Current Post

get_comments do not get a post ID as parameter but rather an array in which you can set all kinds of query criteira including post ID. See the codex http://codex.wordpress.org/Function_Reference/get_comments. You can even use the author_email parameter to make get_comments do most of the work for you.

Show comments in a popup

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 comments_popup_script(). In general, you can … Read more

List user comments in author page

Try with WP_Comment_Query and make sure you have the right Author ID from the Author Template. // WP_Comment_Query arguments $args = array ( ‘user_id’ => $user->ID, ‘post_status’ => ‘approve’, ‘number’ => ’10’, ); // The Comment Query $comments = new WP_Comment_Query; $comments = $comments->query( $args ); // The Comment Loop if ( $comments ) { … Read more

How to return 404 when called edit-comments.php?

There are several ways you can approach this. I wouldn’t recommend deleting edit-comments.php as this is changing the core files, and your changes will be lost when you update WordPress. htaccess 301 Redirect /wp-admin/edit-comments.php http://www.example.com/wp-admin/ OR functions.php Part 1 // Redirect any user trying to access comments page function custom_disable_comments_admin_menu_redirect() { global $pagenow; if ($pagenow … Read more

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