# PHP Helpers

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

- **Category:** Build & Integrate
- **Canonical Guide:** https://pottr.tangble.com/docs/php-helpers

---

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

## Reading Entries

**File: `functions.php`**

```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 );
```

<ul>
<li>`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`.</li>
<li>`pottr_first()` returns the first match or `null`.</li>
<li>`pottr_related( $collection, $field, $id )` returns entries whose relation field points at `$id`.</li>
<li>`pottr_find( $collection, $id )` reads storage directly and returns the stored row, with your fields nested under `data`.</li>
</ul>

## Connecting an App in Process

A plugin can declare its collections without a network call:

**File: `my-plugin.php`**

```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](/pottr/docs/connecting-apps).
