Forum

Thread tagged as: Question

Access content via ID inside custom field type?

I have a set of subpages that I'm trying to create a custom field type for (so I can display a given thumbnail, title and link within a repeater as 'related projects' inside a project page).

Using the pagelist field type as a starting point, I've managed to filter the list to the specific subpages I want. What I'm not sure how to do is use the ItemId for each page to fetch the details for that project (as perch_content_custom isn't available inside a custom field type's class).

I'm guessing I need to grab a method something from one of the Perch class files, but I'm not sure what... does anyone have any tips?

Mike Armstrong

Mike Armstrong 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You could do something like:

if (!class_exists('PerchContent')) {
      include(PERCH_CORE.'/apps/content/PerchContent.class.php');
}
$PerchContent = PerchContent::fetch();
$result = $PerchContent->get_custom($key, $opts);

Be aware that that's not part of the public API, so it could possibly change. It's unlikely to change any time soon, though. It's been that way forever.

Got it - I was very nearly there, but I'd missed out the PerchContent::fetch(); part.

Thanks Drew!