Home Forums General Issues Display selected relationship as a String Reply To: Display selected relationship as a String

  • It was returning an ID, now I’ve changed it to return an object (in the Back-End) and also changed the code, previously I was receiving the following message:

    Trying to get property of non-object in… (same as above).

    The final code:

    $query = new WP_Query($args);
              if ($query->have_posts()) :
                while ($query->have_posts()) : $query->the_post();
              <?php $i = 0;?>
              <?php if($i == 0){ echo "<tr>"; }?>
                 $artista_evento = get_field('artista_del_evento');
                    foreach ($artista_evento as $av) {
                        echo get_the_title( $av->ID );
              <?php $i++;?>
              <td><?php the_field('fecha_del_evento'); ?></td>
              <?php $i++;?>
              <td><?php the_field('lugar_del_evento'); ?></td>
              <?php $i++;?>
              <td><?php echo get_the_content(); ?></td>
              <?php $i++;?>
              <?php if($i == 4){ echo "</tr>"; $i=0;}?>
            <?php endwhile; ?>
            <?php if($i < 4) echo '</tr>'; ?>
    <?php wp_reset_postdata(); ?>