Displays a field with another $post_id

Support General Displays a field with another $post_idResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #34337
    marcodedomarcodedo
    Participant

    I have a custom field in the PRODOTTI post type

    $meta_boxes[] = array(
      'title'      => esc_html__( 'Link Stripe', 'scadenza' ),
      'post_types' => array('prodotti'), // <- post-type PRODOTTI 
    
      'fields' => array(
        array(
          'name'        => 'Link Stripe',
          'id'          => 'stripeUrl',
          'type'        => 'text',
        ),
      )
    );

    In a single post of the DOMINI post type I recall a post from PRODOTTI with type=>post

    $meta_boxes[] = array(
      'title'      => esc_html__( 'Prodotto', 'scadenza' ),
      'post_types' => array('domini'), // <- post-type DOMINI
    
      'fields' => array(
        array(
          'name'        => 'Prodotto singolo',
          'id'          => 'prodotto_singolo',
          'type'        => 'post', // <- type POST
    
          // Post type.
          'post_type'   => 'prodotti',
    
          // Field type.
          'field_type'  => 'select_advanced',
        ),
    
      )
        
    );

    I want to display the value of the 'stripeUrl' field and use this code

    $prodotto = rwmb_meta( 'prodotto_singolo', $post_id );
    if ( $prodotto ) {
      $stripeUrl = rwmb_meta( 'stripeUrl', $prodotto );
    }

    First I load the ID of the 'prodotto_singolo' field and then I want to load the 'stripeUrl' value using $prodotto like $post_id, but no value is displayed.

    Where am I wrong?

    #34352
    Long NguyenLong Nguyen
    Moderator

    Hi,

    If you do not use the second parameter (args) of the helper function, please leave it blank and pass the post ID as the third parameter.

      $stripeUrl = rwmb_meta( 'stripeUrl', '', $prodotto );
    

    Read more on this documentation https://docs.metabox.io/rwmb-meta/

    #34357
    marcodedomarcodedo
    Participant

    Ok, now it works fine!
    Thank you very much!

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