When would you use $_post instead of $post?

I’ve seen some examples that use $_post instead of $post. What’s the difference and when would you use $_post instead of $post?

Example:

if (have_posts()) :
while (have_posts()) : the_post();
if(!in_category("some-category", $_post )) { do_something(); }

2 Answers
2

I’m not certain, but if you’re talking about $_post as seen here:

http://codex.wordpress.org/Function_Reference/in_category

It’s referring to a post ID so they’ve probably added the underscore to avoid confusion. The $post variable is a post object with all the details of the post.

However, $_POST is a global PHP variable containing all the values sent from a form:

http://php.net/manual/en/reserved.variables.post.php

Leave a Comment