PHP - access API, repeater fields & display singletons fields

Hi there!

A php/wordpress dev here. For a few different projects I’ve decided to use Cockpit, as it perfectly fits my needs. I have a single page website with bunch (around 20) different custom fields (here known as Singletons).

What I’m trying to achieve in PHP is to echo / get their values in website main view. So according to few posts / snippets I’ve included the bootstrap.php file at the very beggining of my index.php file. But then I’ve stucked. There is a bunch of Collections-related code snippets, but unfortunatelly I didnt find anything that works for singletons.

Few questions:

  1. If my index file is on the same server as Cockpit, do I need to use API token to display fields and somehow placed in the code? In my settings I do have API key generated + my singletons block (called homepage) is set to public.
  2. What’s the easiest way to show value of text field called e.g. “game_title”?
  3. Where I can find any code examples how to work with repeater fields? few created fields are repeater type so probably a kind of loop here is needed.

I’ve tried sth really basic like this:



$field = $this->module('singletons')->getData('game_default_title');

echo $field;


but it returns an error

Uncaught Error: Using $this when not in object context

THanks for any tips!!