Getting all data from relationship

Support MB Relationships Getting all data from relationshipResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #35433
    Amy SchmidtAmy Schmidt
    Participant

    Hey there,

    I have a relationship between two CPTs. Let's say 'hotels' (wp_hotels) and 'units' (wp_units).

    On the hotel page, I'd like to show all that information, but also information pulled from the units table and not just the title.

    For simplicity, I will use these fields:

    table: wp_hotels
    field: name
    field: city

    table: wp_units
    field: type
    field: date_available

    When I do

    
    $connected = new WP_Query( [
    'relationship' => [
      'id'   => 'units_to_hotels',
      'from' => get_the_ID(), 
    ],
    'nopaging'     => true,
    ] );
    

    I do a printR on $connected, I see the correct units, but not the custom fields.

    On my 'hotel' page, I would like to show:

    Hotel Name
    (city)

    Units In Hotel:
    (type) - (date_available)

    .... essentially, how do I show (type) and (date_available) on the hotel page? Thank you!

    #35434
    Amy SchmidtAmy Schmidt
    Participant

    After doing a bunch of reading here, I think this may have the solution I need.

    https://metabox.io/mb-views-how-to-display-relationships/

    I guess the answer is to just use a helper. I thought I tried the php version of it and it didn’t work but I’ll try again and mess around. Maybe I had a typo

    #35438
    Amy SchmidtAmy Schmidt
    Participant

    Yea you can close this. The helper worked, I must have just been typing something wrong when I first tried.

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