Adding post ID as a field

Support Meta Box AIO Adding post ID as a fieldResolved

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #38320
    Macky McCormackMacky McCormack
    Participant

    Hey,

    I'm trying to add the post id as a field value to a field in a field group that I have already set up using the UI.

    Here is my code which I'm running on every page at plugins_loaded, but it's not working. Can you help?

    
    add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
        $postID = null;
        if ( isset( $_GET['post'] ) ) {
        $postID = intval( $_GET['post'] );
    } elseif ( isset( $_POST['post_ID'] ) ) {
        $postID = intval( $_POST['post_ID'] );
    }
        $meta_boxes[] = [
            'title'      => 'Orders',
            'post_types' => 'Order',
            'fields'     => [
                [
                    'name' => 'Order ID',
                    'id'   => 'orderID',
                    'type' => 'number',
                    'std' => $postID,            
                    ],
            ],
        ];
        return $meta_boxes;
    } );
    
    #38329
    Long NguyenLong Nguyen
    Moderator

    Hi,

    If the code does not work on your site, you can also use the action hook rwmb_after_save_field to update a field value after saving the post. Please read more on the documentation https://docs.metabox.io/actions/rwmb-after-save-field/

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.