Custom Fields
Support General Post ID within rwmb_meta_boxes filter

  • Creator
  • #11914
    Resolved jcleaveland


    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:

    What am I missing here?

    Thanks for the help!

Viewing 1 replies (of 1 total)
  • Author
  • #11915
    Anh Tran

    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 1 replies (of 1 total)
  • You must be logged in to reply to this topic.