This type of display looks deceptively simple. To accomplish it in Views takes several steps.
Step 1: We need to create a list IDs of all the Companies related to this project. Something like 1,2,3,4.
- Create a View of Architects filtered by post relationship, where the parent is the current page (i.e. the Project)
- In the Loop, insert the post ID of the parent Company using the wpv-post-id shortcode like this:
<wpv-loop>
[wpv-item index=1][wpv-post-id id="$company"]
[wpv-item index=other],[wpv-post-id id="$company"]
</wpv-loop>
- Replace $company with "$" plus the company post type slug, if it's not "company".
- This should produce a list of Company IDs, but it will include some extra markup we do not want. So add this filter to your child theme's functions.php file:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
function prefix_clean_view_output( $out, $id ) {
$ids = array( 12345 );
if ( in_array( $id, $ids )) {
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if (
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
} else {
$start = strpos( $out, '>' );
if ( $start !== false) {
$out = substr( $out, $start + 1 );
$end = strpos( $out, '<' );
$out = trim(substr( $out, 0, $end ));
}
}
}
return $out;
}
- Replace 12345 with the numeric ID of the View of Architects.
- Place this View somewhere on the Project page, and check that it outputs the correct Company IDs. It's okay if there are duplicates.
Let me know if you are able to get this far, and then I'll go into the next step.