Created
November 27, 2016 20:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) | |
?> |
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
Thanks a lot for this. Helped a lot.