Post ID within rwmb_meta_boxes filter

Support General Post ID within rwmb_meta_boxes filterResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #11914
    jcleavelandjcleaveland
    Participant

    Hi,

    I thought htis would be simple, but I cannot figure out how to get the current post_id within the rwmb_meta_boxes filter.

    I need the post ID to pass to a function that will create the placeholder for the select box based on what user role of the author of the post. Thus, I need the post_id to determine the author_id to get the author role.

    I create the options for the field using a function that calls current_user_can and it works just fine, so I know that I should be able to grab the post id somehow... I'm just missing it somewhere.

    Things I have tried are below:

    https://ghostbin.com/paste/6yaxf

    What am I missing here?

    Thanks for the help!

    #11915
    Anh TranAnh Tran
    Keymaster

    Hi Jason,

    The problem is meta boxes are registered and run before any WP query, so all the template functions won't work.

    If you're going to get in the back end, then please use this code:

    $post_id = false;
    if ( isset( $_GET['post'] ) ) {
        $post_id = intval( $_GET['post'] );
    } elseif ( isset( $_POST['post_ID'] ) ) {
        $post_id = intval( $_POST['post_ID'] );
    }
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.