Skip Navigation

[Resolved] Finding intermediary post custom fields

This support ticket is created 2 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 reply, has 1 voice.

Last updated by michielM 2 years, 5 months ago.

Author
Posts
#2402747

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!

#2402765

My issue is resolved now. Thank you!