Getting data from a field in a related post

Support MB Relationships Getting data from a field in a related post

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #40254
    dhknyc@gmail.com[email protected]
    Participant

    Hi
    I am using Bricks with Metabox AIO. I have 2 CPT "events" and "Rooms". I have a relationship between them and using bricks I can successfully get event info as well as a link to the related room where the event is. So far so good.
    I would like to add location information (a field in the Rooms CPT ) to the output and am having trouble.

    The following code produces empty results.

    function jp_search_customfield_related($customfield_ID, $relationship_ID) {
    global $post;
    $connected_posts = MB_Relationships_API::get_connected([
    'id' => $relationship_ID,
    'to' => $post->ID,
    ]);
    // if there are no connected , abort
    if (empty($connected_posts)) {
    return $connected_posts;
    };
    foreach ($connected_posts as $connected_post){
    $connected_posts_ids[] = $connected_post->ID;
    };
    $customfield = rwmb_get_value($customefield_ID, '', $connected_posts_ids[0]);
    return($customfield);
    }

    Any help is appreciated. As you can probably see I am not an expert.

    Thank you in advance
    Dirk

    #40262
    PeterPeter
    Moderator

    Hello Dirk,

    You can try to pass a specific post ID to the helper function and see if it works correctly.

    $customfield = rwmb_get_value($customefield_ID, '', 123);

    If it works, there should be something wrong with the array $connected_posts_ids.

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