theme development - Comment status shows 'closed' in db, but it shows 'open' when i echo it

admin2025-06-02  1

Here is database ss. And comment_status is closed

But when i print it, it shows open

echo $post->comment_status;

Also, in page settings, comments checkbox is unchecked.

So, i can't hide comments in pages. How can i fix it?

Here is database ss. And comment_status is closed

But when i print it, it shows open

echo $post->comment_status;

Also, in page settings, comments checkbox is unchecked.

So, i can't hide comments in pages. How can i fix it?

Share Improve this question edited Mar 5, 2019 at 10:53 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Mar 5, 2019 at 9:11 wpdevwpdev 5492 gold badges13 silver badges28 bronze badges 2
  • Are you sure, that you're printing comment_status for the same post? Maybe there is a custom wp_query that is modifying the global $post variable? – Krzysiek Dróżdż Commented Mar 5, 2019 at 10:32
  • Yes you are right. I put another query in this page template and $post not see page ID. It gets $post from first post of custom query. – wpdev Commented Mar 5, 2019 at 10:49
Add a comment  | 

1 Answer 1

Reset to default 2

First thing I would do to debug such case is printing $post->ID just before printing the comment status. (And make sure if it is equal to 414 - the post you’re checking in DB)

I’m almost certain that somewhere in your page you make another wp_query and modify the global $post variable. So when you’re printing the comment status it’s showing the real value but for different post.

If you do such wp_query, then you'll have to remember to use wp_reset_postdata after that loop, so the global $post variable is restored to its original value.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748841430a314170.html

最新回复(0)