Stressing Over Blank Comments In WordPress

OMG! Better post this as a record for myself later and hopefully be helpful to you if you have a similar problem.

So… client sends SOS about WordPress comments not working. I figure this is probably something simple – when will I ever learn?

I run through the most common possibilities.

Miedo
Photo credit:
Arturo J. Paniagua

Check it for myself – not it’s not that I don’t trust clients words but sometimes when the code gods takes pity on you, they help you out, and the problem fixes itself. After all, why spend time fixing something when there is no problem right (and save clients some billable hours – I’m way too nice).

Problem not resolved. Time to get to work.

Comments not turned on? Could be, checked them comments are on globally and on each post.

Pop open the theme. Checked comments.php, nothing out of the ordinary.

Disabled plugins. Re-submit comment. No dice. Not plugin issue. Turned on default theme. Default theme works. Yay! At least I’m hitting some progress. It’s got to be the theme. But where?

Check for spaces and junk. Opened up theme files, wp-config.php, functions.php, wp-comments-post.php checked for additional spaces after ?>.

Aha! functions.php missing a closing ?> tag. Cleaned up all the other files.

Still nothing!

Search for solutions. Googled and searched WordPress.org. None of them were relevant or related. This cannot be!

By now, I’m getting a little pissed.

Made wp-post-comments.php tell me where the problem was. Put in error_log() so it can output errors. One error! Good. It was a plugin. So I disabled that plugin again – not very confident because I’d done it before and didn’t help. But what the heck, try it anyway.

No change and what’s worse, I now have no errors. Argh!

Asked for theme developer support area – the suggestion – reload the theme again. What?! I cannot do that. I’ve added or changed like 500 lines of code. Ugh.

Abandon suggestion. Instead, I load it the theme into my sandbox blog. It works! What the heck is going on?

By now I have a sinking sensation that I may have to back track every single thing I spent the last oh several months working on. I… just… can’t.

Now I’m angry.

Captain
Photo credit:
pusgums

Time to get creative but decided to give WordPress.org forums one more go. Miraculously, a new item popped up that didn’t before. The thread went on to discuss the possibilities that were new, along a path I hadn’t tried before.

That’s a good sign. I tried the suggestion. No dice.

But, it gave me a new clue. Using the knowledge and experience from developing several WordPress themes and sites, I tried my idea.

Woo Hoo! Success! Does a happy dance.

Solution:

For those of you who are technical and facing a similar issue here’s the deal. WordPress comments uses the post ID to track which comments are attached to which posts and also to redirect people back to the post after submission.

If a post ID is missing somewhere, comments either break or users are redirected to a blank page after submission because it doesn’t know where to redirect people to.

On this page in Codex (scroll to the very bottom), it tells you to make sure the code is there. It is.

On a hunch, I decided to check if the code is outputting properly. View source is an amazing tool. Sure enough the code is not writing the post ID to the form instead of

<input type="hidden" name="comment_post_ID" value="123" />

it was outputting

<input type="hidden" name="comment_post_ID" value="Array" />

Now, normally I would figure out why but time is not on my side, client getting antsy. The next best option is to try a different way to output the code. Instead of what Codex gives me which is

<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />

I used

<input type="hidden" name="comment_post_ID" value="<?php the_ID(); ?>" />

but that didn’t work out. I knew there was another way to output the post ID so tried this.

<input type="hidden" name="comment_post_ID" value="<?php echo $post->ID; ?>" />

That worked for me. Hope it works for you too. Good luck.

Scroll to Top