$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme development - Comment status shows 'closed' in db, but it shows 'open' when i echo it|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin9PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far