WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I made some changes in comment-template.php, wp-comment-post.php so now I am storing the comments withot attaching with any post or page (I am setting the comment_post_id to 0). But now the problem is When I go on admin panel and see all comments the comments with 0 comment_post_id are not having option of spam , trash , approve etc. how to resolve it?

Actually I want to store comments separately from post or page but with complete functionality as in comments of any post or page like whether logged in or not otherwise fields for name, email etc. and in admin panel options for approval,trash,spam etc..

Can I achieve this with any other plugin that performs same as comment form.

share|improve this question
I don't know if this is workable, but maybe instead of attaching to non-existent id=0, create a post (id=23243 or whatever), and attach all comments to that post. You could even hide the post from the loop. I haven't thought this through too far, but it might be doable. – akTed Jan 15 '13 at 8:44
@AKTed this will not work too because there is no post with id = 23243 – Bhuvnesh Gupta Jan 15 '13 at 9:07
@Bhuvnesh simply create a dummy post and use that post id, if you don't want to exclude the post then create a post type just for that dummy post and make it none public. – Bainternet Jan 15 '13 at 9:19
@Bainternet I can do this thanx! but it will be more good if I got some other solution instead of using post means is there any plugin or any other way to achieve my question goal. Please help me if you can. Thanks in advance – Bhuvnesh Gupta Jan 15 '13 at 9:28
I was trying say create a post and use the id that is automatically assigned to it (id=23243 or whatever) instead of using a non-existent post id=0, but it didn't come out so clear. – akTed Jan 15 '13 at 9:52
up vote 0 down vote accepted

I found a way to hijack the comment before it's attached to its post in the DB. Using the snippet below you can attach every comment to your dummy post. Just change COMMENT_ID to the ID of your dummy post. No hacking of core needed!

add_filter('preprocess_comment', 'akt_hijack_comment');
function akt_hijack_comment($comment) {
    define('AKT_REDIRECT_URL', $comment['comment_post_ID']);
    $comment['comment_post_ID'] = 63;
    return $comment;
add_filter('comment_post_redirect', 'akt_redirect');
function akt_redirect($location) {
    return get_permalink(AKT_REDIRECT_URL);

A side-effect that I haven't tried fixing yet: after submission of the comment, the user is redirected to the dummy post. Not sure if I'll have time to figure it out tonight.

I edited the code to redirect the user back to the same page that was commented on.

Edit: You can make this into a plugin (add // Plugin Name: SOME_NAME under <?php) or a mu-plugin (paste as into a file and upload it to wp-content/mu-plugins - create mu-plugins directory if needed). Or you can paste into the functions.php of your theme (least desirable method).

share|improve this answer
redirestion is easy just use wp_safe_redirect( "index.php" ); in wp-comments-post.php file – Bhuvnesh Gupta Jan 15 '13 at 11:37
but where to use the above code which you give me in answer – Bhuvnesh Gupta Jan 15 '13 at 11:39
Yeah, but that might throw user off to end up at a different page. Probably better to hook into where it does the redirect, wp-comments-post.php, line 96. Hook into comment_post_redirect. – akTed Jan 15 '13 at 11:41
@Bhuvnesh I edited the Question with directions. – akTed Jan 15 '13 at 11:46
@Bhuvnesh: You seem determined to hack WP core files, but that's not a good idea; there's almost always a more elegant way to do it. I figured out how to redirect correctly. See the updated code. – akTed Jan 15 '13 at 12:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.