function get_lessons_for_speaker_func(){
ob_start();
global $post;
$speaker_id = $post->ID;
$relationship_slug = 'lesson-speaker';
$child_posts = toolset_get_related_posts(
$speaker_id , // get posts connected to this one
$relationship_slug, // in this relationship
array(
'query_by_role' => 'child', // origin post role
'role_to_return' => 'parent', // role of posts to return
'return' => 'post_object', // return array of IDs (post_id) or post objects (post_object)
'limit' => 999, // max number of results
'offset' => 0, // starting from
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'publish',
'need_found_rows' => false, // also return count of results
'args' => null // for adding meta queries etc.
)
);
$arr_m = array_map(function($o) { return "<li><a href='" . get_permalink($o->ID). "'>$o->post_title</a></li>"; }, $child_posts);
$output_string = join(", ", $arr_m);
ob_end_clean();
return "<ul>$output_string</ul>";
}
add_shortcode('get_lessons_for_speaker','get_lessons_for_speaker_func');
The shortcode shows posts which are on draft or supposed to be published in the future.
$relationship_slug = 'lesson-speaker';
$child_posts = toolset_get_related_posts(
$speaker_id, // get posts connected to this one
$relationship_slug, // in this relationship
array(
'query_by_role' => 'child', // origin post role
'role_to_return' => 'parent', // role of posts to return
'return' => 'post_object', // return array of IDs (post_id) or post objects (post_object)
'limit' => 999, // max number of results
'offset' => 0, // starting from
'orderby' => 'title',
'order' => 'ASC',
'need_found_rows' => false, // also return count of results
'args' => array(
'post_status' => 'publish',
),
)
);