I'm trying to display the titles of custom post types that are linked to an intermediay post via an intermediary post custom field.
Custom Post Types are:
Leerling (student)
Locatie (location)
Workshop
Intermediary Post Type
Leerling (parent) - Locatie (child)
Custom field
workshop-leerling-locatie (single line)
Students choose per Location which Workshop they wanna attend, which is stored in the Intermediary Post Custom Field as the Workshop post ID. I would like to show on my page (it will become a csv file eventually) all the choices any student made for each of the Locations.
Ideally I would have used a view, but as nested shortcodes apparently don't work (i.e. [wpv-view name="test" wpvrelatedto="[wpv-post-id]"]), I had to resort to a custom shortcode. Here is that code:
add_shortcode('get_student_choices', 'func_get_student_choices');
function func_get_student_choices($atts) {
$result = "";
$leerling_id = do_shortcode("[wpv-post-id]");
$dagschema_id = do_shortcode("[wpv-post-id item='@dagschema-leerling.parent']");
$cur_students_locs = toolset_get_related_posts(
$leerling_id,
'leerling-lokatie',
[ 'return' => 'post_object',
'query_by_role' => 'parent',
'role_to_return' => 'intermediary',
] );
$results = count($cur_students_locs);
foreach ($cur_students_locs as $studentlocation) {
print_r($studentlocation);
$results = $studentlocation["ID"];
}
return "<td>" . $results . "</td>";
}
But whatever I do, I don't seem to get results from the $studentlocation inside the foreach.
What am I doing wrong? Hope you can help!
My issue is resolved now. Thank you!