Last active
December 11, 2015 07:48
-
-
Save cameronbaney/4568453 to your computer and use it in GitHub Desktop.
This is for getting relationships in WordPress
This file contains hidden or 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 | |
// Variable for post ID | |
$pID = '"' . $post->ID . '"'; | |
// Query the relationship | |
$relpa = new WP_Query(array('post_type'=>'page','posts_per_page'=>'-1','post_parent'=>'6', | |
'meta_query'=>array( | |
array( | |
'key' => 'rel_attorney', // This is the custom field's name | |
'value' => "$pID", // This is the post ID of the current page you're on | |
'compare' => 'LIKE' | |
) | |
)) | |
); | |
// Check if there are any relationships | |
if($relpa->found_posts){ ?> | |
<h2 class="rel-title">Practice Areas</h2> | |
<ul class="rel-list"> | |
<?php } | |
// The loop | |
while ( $relpa->have_posts() ) : $relpa->the_post(); ?> | |
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> | |
<?php endwhile; | |
// Check if there are any relationships (this is done again to close out the ul) | |
if($relpa->found_posts){ ?> | |
</ul> | |
<?php | |
} // Close the check if there are any relationships if statement | |
wp_reset_postdata(); // Reset the post | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment