Last active
August 29, 2015 14:07
-
-
Save kristianb21/63970268164f9b40ac6d to your computer and use it in GitHub Desktop.
wp display post relationships
This file contains 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 | |
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