Reputation: 1056
Is it possible to display a template for a related pod?
$mypod = pods('custompage', 'page-slug');
$related_pod = $mypod->field('top_feature');
Now I want to call something like
$related_pod->template('FeatureTemplate');
I can't seem to find a solid answer in this docs, is this possible?
Upvotes: 0
Views: 64
Reputation: 3558
What you are trying to do will not work. The problem is that $related_pod
is not an object of the Pods class, and therefore you can not call the method template()
on it.
It is possible to use the ID of the related item to build a second Pods object for the related post, which we can then call the method template()
on. Normally we wouldn't do this because we don't need to and its not the most performant way of working.
Here is how you can do this. IMPORTANT: this assumes that "top_feature" is a single select field, as it is in OP's case. This will not work for a multi-select field.
```
$mypod = pods( 'custompage', 'page-slug' );
$relationship_field = $mypod->field( 'top_feature' );
if ( $relationship_field ) {
//get ID of related item
//Depending on content type you may need to use, 'id', instead of 'ID'
$related_item_id = pods_v( 'ID', $relationship_field );
$related_pod = pods( 'name_of_related_pod', $related_item_id, true );
if ( is_a( $related_pod, 'Pods' && $related_pod->id() === $id ) ) {
$related_pod->template( 'FeatureTemplate' );
}
}
```
Upvotes: 1