I am creating a WP plugin based around Custom Post Types (CPT), where you can dynamically specify a CPT, complete with any number of associated dynamic Meta Boxes and form elements such as radio buttons, textfields etc.., using the excellent Meta Box Script V3.1 from RilWis.

The issue I am having is that I need to recover the post ID of a CPT "post" in WP-admin before I issue the add_action hook command to build the dynamic Meta Boxes.

It appears that WP only starts allowing the recovery of the post ID (in admin) from the parse_query action hook command onwards in the firing sequence of WP. However the Meta Box script by Rilwis has a save_post action command (naturally), which only triggers up until the admin_init action hook.

This means there is no overlap in the WP admin firing sequence to allow the postID to be recovered (to find the data required to build further CPT's dynamically) before the call to build them is needed.

Short of abandoning Rilwis WP Meta Box class, and developing a Meta Box data save functionality of our own (or my lack of WP understanding), can anyone give me some thoughts on how I can recover the post ID earlier in the WP admin hook firing sequence? Or conversely whether we can trigger an action to save the Meta Box post data later in the WP firing sequence?

  • This sounds like an interesting problem. I've dealt with similar things before. I'm having trouble understanding when and where you need to grab the ID. Can you post a code snippet to give me a better idea of where this is occurring and what you are trying to do.
    – tollmanz
    Commented May 1, 2011 at 15:32

2 Answers 2


If you're talking about on post pages in admin, couldn't you just grab id from url?

$post_id = $_REQUEST['post'];

Not sure if it will be available during that hook, but I normally make the $post object global and get the post id from that:

global $post;
$this_post_id = $post->ID;

$post is an object that the WordPress core uses to store the current post info. You should be able to use that; thats actually what RilWis uses in his class.

  • Hi Manny, Thanks very much for responding so quickly. Yeah... I have been using the global $post already to recover the post ID via $post->ID, however I can only start to get a result after requesting it via the "parse_query" add_action hook for some reason. Do you know of anyway to get a result for $post->ID before this hook? Commented May 1, 2011 at 14:47
  • It might not be available before that. Not too sure Commented May 1, 2011 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.