Skip to content

Instantly share code, notes, and snippets.

@l00f00
Created October 22, 2022 12:24
Show Gist options
  • Save l00f00/53e64f417e2679e7afe3832e11243135 to your computer and use it in GitHub Desktop.
Save l00f00/53e64f417e2679e7afe3832e11243135 to your computer and use it in GitHub Desktop.
metabox relationships fileds get all the posts related based on matching relationship
<?php
$getartist = new WP_Query( [
'relationship' => [
'id' => 'opera_artist_relationship',
'from' => get_the_ID(),
],
'nopaging' => true,
] );
while ( $getartist->have_posts() ) : $getartist->the_post();
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
$getallartworks = new WP_Query( [
'relationship' => [
'id' => 'opera_artist_relationship',
'to' => get_the_ID(),
],
'nopaging' => true,
] );
while ( $getallartworks->have_posts() ) : $getallartworks->the_post();
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
endwhile;
wp_reset_postdata();
endwhile;
wp_reset_postdata();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment