Skip to content

Instantly share code, notes, and snippets.

@mwhiteley16
Created April 11, 2019 12:16
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 mwhiteley16/37d6c52ecc2867a8463b579bef581697 to your computer and use it in GitHub Desktop.
Save mwhiteley16/37d6c52ecc2867a8463b579bef581697 to your computer and use it in GitHub Desktop.
single-communities.php
<?php
$neighborhoods = get_posts(
array(
'post_type' => 'neighborhoods',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'wd_community_relationship', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
)
); ?>
<?php if( $neighborhoods ): ?>
<div class="widget widget_nav_menu">
<h3>Neighborhoods in <?php the_title(); ?></h3>
<ul>
<?php foreach( $neighborhoods as $neighborhood ): ?>
<li>
<a href="<?php echo get_permalink( $neighborhood->ID ); ?>">
<?php echo get_the_title( $neighborhood->ID ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment