-1

How can I use fields from the second pod record based on the value from the relationship field in the first pod?

Let's say I have a pod called countries with fields country_name and country_language

In the second pod called languages I have fields language_name and language_flag


country_language field is a relationship field dropdown with values from languages (language_name)

What I want is to somehow be able to echo the language_flag field (corresponding to language_name of that row) when using this code:

<?php
     $params = array(
        'limit'   => -1
     );
     $countries = pods( 'countries', $params );

     if ( 0 < $countries->total() ) {
          while ( $countries->fetch() ) {
?>
     <h2><?php echo $countries->field( 'country_name' ); ?></h2>
     <br>
<?php
          } 
     } 
?>

I was thinking that something like this could work but of course it doesn't:

<h2><?php echo $countries->field( 'country_name' ); ?></h2>
<img src="<?php echo $countries->field( 'languages.language_flag' ); ?>">
<br>

I am uusing PODS 2 and trying to display the results in my theme's header.php.

Adrian Heine
  • 4,051
  • 2
  • 30
  • 43
Derfder
  • 3,204
  • 11
  • 50
  • 85

1 Answers1

1

If language_flag is a file field, you might want to be using languages.language_flag.guid instead.

Pods 2.0 has a new function available too, which is $countries->display( 'field_name' ) so you could try checking that out too.