Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save giodc/267743f28802c52c260fe6f34f39fb91 to your computer and use it in GitHub Desktop.
Save giodc/267743f28802c52c260fe6f34f39fb91 to your computer and use it in GitHub Desktop.
Use WP-query in WordPress to retrieve Pods Relationship Custom Post Type Content
<?php
//get Pods object for current post
$pod = pods( 'room', get_the_id() );
//get the value for the relationship field
$related = $pod->field( 'hotel' );
//loop through related field, creating links to their own pages
//only if there is anything to loop through
if ( ! empty( $related ) ) {
foreach ( $related as $rel ) { ?>
<?php
//get id for related post and put in ID
//for advanced content types use $id = $rel[ 'id' ];
$id = $rel[ 'ID' ];
$content = get_post_field('post_content', $id);
?>
<?php
$args = array(
'p' => $id,
'post_type' => 'any');
// La Query
$the_query = new WP_Query( $args );
// The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
the_content();
endwhile;
wp_reset_query();
wp_reset_postdata();
?>
<?php } //end of foreach
} //endif ! empty ( $related )
?>
@giodc
Copy link
Author

giodc commented Nov 9, 2022

Thanks a lot for this. Helped a lot.

Glad to help!

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