Derfder
Derfder

Reputation: 3324

How to join 2 pods in PODS 2 framework?

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.

Upvotes: -1

Views: 956

Answers (1)

Scott Kingsley Clark
Scott Kingsley Clark

Reputation: 987

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.

Upvotes: 1

Related Questions