Getting subfield of "post" field type

Support MB Custom Post Type Getting subfield of "post" field typeResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #47401
    sandrinerodriguessandrinerodrigues
    Participant

    Hello,

    I have 2 CPT "concert" and "artiste".

    I am using Oxygen Builder and am trying to link a concert with several artists, in order to display their biography (content), title, photo (thumbnail image) and other custom fields.

    I decided to use the "post" field type, cloneable to get the artists as concert fields.
    (I was thinking of using MB relationships but didn't manage to make it work)

    I try to display their biography and instrument in a code block :

    <?php $post_ids = rwmb_meta( 'artiste_s_associe' ); 
      
      foreach ( $post_ids as $post_id ) : 
        $nom_artiste = get_the_title( $post_id );
        $instrument = rwmb_meta( 'instrument' );
        $biographie = get_the_content( $post_id );
        $photo = get_the_post_thumbnail_url( $post_id);
    ?>
        <h3><?php echo $nom_artiste; ?> - <?php echo $instrument; ?></h3>
            <div> <?php echo $biographie; ?>
    <?php endforeach
    ?>

    The value $nom_artiste displays the correct names, but I cannot reach out to have the content, it displays the content of the global post ID. Which function should I use ? Also, the custom fields are not showing, I suppose it's the same problem.

    Could you tell me where I am wrong ?

    Thank you,

    #47420
    PeterPeter
    Moderator

    Hello,

    Please notice that, we only support issues that are related to Meta Box itself. If you have an issue with a WordPress function or WordPress-related issue, please create a topic in a WordPress support forum https://wordpress.org/support/forum/how-to-and-troubleshooting/

    Regarding "the custom fields are not showing", you can pass the variable $post_id to the third parameter of the helper function rwmb_meta() to get a field value of a specific post.

    `$instrument = rwmb_meta( 'instrument', '', $post_id );

    Following the documentation https://docs.metabox.io/functions/rwmb-meta/

    #47422
    sandrinerodriguessandrinerodrigues
    Participant

    Thank you Peter, I made it work.

    And for the WordPress function, I found the solution, of course it was not related to Metabox.
    Regards,
    Sandrine

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