[wp-hackers] $postnow?

Mike Schinkel mikeschinkel at newclarity.net
Wed Sep 22 06:32:25 UTC 2010

Hi Ozh,

Thanks for the suggestion.  I had definitely overlooked $id.

Unfortunately I just checked and global $id is null when I need it, at least for this one use-case, but possibly for others too.

My specifics?  In /wp-admin/post.php when admin_init is called global $id is null.

My use-case?  My client wants me to disable most of the standard metaboxes for post_type='page' except in some cases we are going to add metaboxes, and we've decided to key the metabox selection logic to the page template.  But in order to determine the current page template I need to be able to first determine what the current post ID is.

FYI, here's the function I wrote for this (which I actually need in numerous other contexts) but it seems like being able to determine the current post ID in a robust and reliable fashion should be someone managed by core?

function get_post_now() {
	static $post_id;
	if (!isset($post_id)) {
		$post_id = false;
		if (isset($_GET['post']) && is_numeric($_GET['post']))
			$post_id = $_GET['post'];
		if (!$post_id && isset($_POST['post_ID']) && is_numeric($_POST['post_ID']))
			$post_id = $_POST['post_ID'];
	return $post_id;


On Sep 22, 2010, at 2:14 AM, Ozh wrote:

>> And there may be other ways I've missed.  Am I overlooking something obvious?  Is there some way to determine the $post->ID that I can depend on?
> global $id ?
> -- 
> http://ozh.org/
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list