Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelbrazell/9d0fe5774b3d0ae0b8b7 to your computer and use it in GitHub Desktop.
Save michaelbrazell/9d0fe5774b3d0ae0b8b7 to your computer and use it in GitHub Desktop.
<?php
/**
* I am creating a function here because I am calling it in my template
* using custom_header_template();
* but you do not need to do this
* Additionally, I have a lot of fields that I need to pull in, so I am assigning each one as a variable
* One of those fields is an image and I need the URL so I use the pods_image_url filter
* Additionally, I have a WYSYWIG that has custom shortcodes in it, so I have to use do_shortcode(); to call that field for the shortcode to be executed
*/
if ( ! function_exists( 'custom_header_template' ) ) :
function custom_header_template() {
// This is being called outside the loop, so I'm introducing global $post and calling $post->ID;
// Fill in "pod_name" with your pod name
global $post; $pod = pods( 'pod_name', $post->ID );
// Call your relationship field here
$related = $pod->field( 'relationship_field_name' );
if ( ! empty( $related ) ) {
$id = $related['ID'];
// I'm declaring variables to use.
$page_header_image = pods_image_url( get_post_meta( $id, 'page_header_image', true ), 'original' );
$page_header_intro = get_post_meta( $id, 'page_header_intro', true);
$page_header_text_color = get_post_meta( $id, 'page_header_text_color', true);
$page_header_accent_strip = get_post_meta( $id, 'page_header_accent_strip', true);
$page_header_top_margin = get_post_meta( $id, 'page_header_top_margin', true);
$page_header_bottom_margin = get_post_meta( $id, 'page_header_bottom_margin', true);
// Next I'm going to build my HTML
?>
<div class="main-container">
<div class="background-image" style="background-image:url(<?php echo $page_header_image; ?>);"></div>
<section id="intro" style="color: <?php echo $page_header_text_color; ?>">
<?php echo do_shortcode($page_header_intro); ?>
</section>
</div>
<div class="header-accent-row" style="background-color: <?php echo $page_header_accent_strip; ?>;"></div>
<?php
}
}
endif;
?>
@sc0ttkclark
Copy link

You could do $related = get_post_meta( $post->ID, 'relationship_field_name.id', true ); (no third argument, or set third argument to it's default of false if you need to get multiple items back)

or .ID if it's a post type or user, see more variations you may want to be cognisant of for the ID field's exact name or capitalization here: http://pods.io/docs/code/pods/find/#additional-information

@michaelbrazell
Copy link
Author

Ohh, this is great thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment