Skip to content

Instantly share code, notes, and snippets.

@kristianb21
Last active August 29, 2015 14:07
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 kristianb21/63970268164f9b40ac6d to your computer and use it in GitHub Desktop.
Save kristianb21/63970268164f9b40ac6d to your computer and use it in GitHub Desktop.
wp display post relationships
<?php
types_child_posts($post_type, $args)
/*
$post_type – a string with the name of the child items to load. Since a parent may have children of different types, this argument is required.
$arg – optional, with additional query arguments.
For example, to load ‘room’ child items:
*/
$child_posts = types_child_posts('room');
foreach ($child_posts as $child_post) {
echo $child_post->post_title;
echo $child_post->fields['description'];
}
/*
If you need more control of the returned posts you can create a query directly.
This example returns all rooms that belong to the current property
and will sort them by the description field.
*/
$childargs = array(
'post_type' => 'room',
'numberposts' => -1,
'meta_key' => 'wpcf-description',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(array('key' => '_wpcf_belongs_property_id', 'value' => get_the_ID()))
);
$child_posts = get_posts($childargs);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment