Pottr/Docs
Topic:PHP Helpers
Build & Integrate
.md

PHP Helpers

Read Pottr data from themes and plugins on the same WordPress site without HTTP requests.

Reading Entries

functions.php
$entries = pottr_get( 'project', [
    'where' => [ 'status' => 'active' ],
    'limit' => 10,
] );

$first = pottr_first( 'project', [ 'where' => [ 'title' => 'My Project' ] ] );
$tasks = pottr_related( 'task', 'project_id', 42 );
$entry = pottr_find( 'project', 42 );
  • pottr_get( $collection, $args ) returns a list of flattened entries (id, created_at and your fields). Arguments include where, limit, offset, order_by and order.
  • pottr_first() returns the first match or null.
  • pottr_related( $collection, $field, $id ) returns entries whose relation field points at $id.
  • pottr_find( $collection, $id ) reads storage directly and returns the stored row, with your fields nested under data.

Connecting an App in Process

A plugin can declare its collections without a network call:

my-plugin.php
$result = pottr_connect_app( [
    'app'         => 'my-plugin',
    'name'        => 'My Plugin',
    'collections' => [
        [ 'slug' => 'events', 'name' => 'Events', 'fields' => [
            [ 'key' => 'title', 'type' => 'text', 'required' => true ],
        ] ],
    ],
] );

if ( 'approved' === $result['status'] ) {
    $public_key = $result['public_key'];
} elseif ( 'pending' === $result['status'] ) {
    // Queued for one-click approval in the Pottr dashboard.
}

When the current user is an administrator, collections are created immediately. Otherwise the request waits for approval, as described in Connecting Apps.