I'm trying to order the array returned by the types_child_posts() funtion by using orderby => meta_value_num, but I'm getting no results. Can this paramter be used for this function?
$args = array(
'order' => 'ASC',
'orderby' => 'meta_value_num',
'meta_key' => 'wpcf-performance-date'
);
$child_posts = types_child_posts('festival-performance',$args);
foreach ($child_posts as $child_post) {
Hi Branigan,
This is because the types_child_posts() function is already using the meta_key for querying the parent.
You can try to query childs directly with get_posts and use the meta_query argument instead. Something like this should work:
$childargs = array(
'post_type' => 'festival-performance',
'numberposts' => -1,
'order' => 'ASC',
'orderby' => 'meta_value_num',
'meta_key' => 'wpcf-performance-date'
'meta_query' => array(array('key' => '_wpcf_belongs_producer_id', 'value' => get_the_ID()))
);
$child_posts = get_posts($childargs);
Please let me know if there is anything else that I can assist you with.
Regards
Luo
Thanks for your help - I'll give that a go. Would it also be possible to use these arguments/parameters in a wp_query() ?
Thanks for your assistance
Where i can put this code? In witch archive?
$childargs = array(
'post_type' => 'festival-performance',
'numberposts' => -1,
'order' => 'ASC',
'orderby' => 'meta_value_num',
'meta_key' => 'wpcf-performance-date'
'meta_query' => array(array('key' => '_wpcf_belongs_producer_id', 'value' => get_the_ID()))
);
$child_posts = get_posts($childargs);
In the same as:
$child_posts = types_child_posts('documentacion');
foreach ($child_posts as $child_post) {
echo $child_post->post_title;