Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 May 1 '11 at 15:32
add comment

2 Answers

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

$post_id = $_REQUEST['post'];
share|improve this answer
    
This works for custom post types also. –  KDM May 31 '12 at 7:36
add comment

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.

share|improve this answer
    
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? –  NotLostJustHiking May 1 '11 at 14:47
    
It might not be available before that. Not too sure –  Manny Fleurmond May 1 '11 at 18:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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