Search by

sleak / query

adamalexandersson

WordPress post and term entities, query builders, and flat registration discovery for the Sleak theme.

Package info

github.com/sleak/query

Type:package

pkg:composer/sleak/query

Statistics

Installs: 15

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 1

v1.0.2 2026-11-30 15:51 UTC

This package is auto-updated.

Last update: 2026-11-30 16:04:28 UTC


README

WordPress posts and terms as entities, with query builders and nested registration discovery. Concrete classes such as Post, Page, and Category stay in the theme so a site can add its own methods.

Install

composer require sleak/query

Acorn discovers Sleak\Query\QueryServiceProvider. Publish config with:

wp acorn vendor:publish --tag=sleak-query-config

Point builtins at the theme entity classes:

'builtins' => [
    'post' => App\PostTypes\Post::class,
    'page' => App\PostTypes\Page::class,
    'attachment' => App\PostTypes\Attachment::class,
    'category' => App\Taxonomies\Category::class,
    'post_tag' => App\Taxonomies\Tag::class,
],

Query

Post::query()->published()->where('featured', true)->paginate();

withFields(), withMeta(), and withContent() control hydration. first() always processes content. paginateIds() returns serializable IDs.

Scopes are scope* methods on the entity. whereMeta() omits value for EXISTS and NOT EXISTS.

ACF fields come from Sleak\Query\Contracts\FieldResolver. The default is AcfFieldResolver when get_fields() exists, otherwise NullFieldResolver. Bind another implementation in the container.

PostEntity::terms($taxonomy) returns a TermCollection. Category and tag helpers belong on the theme's Post class.

Discovery

Registration classes live next to their entities (EventType.php and Event.php). #[Entity(Event::class)] links them. The slug is the registration class's $post_type_slug or $taxonomy_slug. An entity with no slug throws UnmappedEntityException.

query:clear drops the cached map. make:posttype Car writes app/PostTypes/Cars/PostType.php and Car.php. make:taxonomy Genre writes app/Taxonomies/Genres/Taxonomy.php and Genre.php. Theme stubs in stubs/ override the package stubs (vendor:publish --tag=sleak-query-stubs).

Registering a post type dispatches Sleak\Query\Events\PostTypeRegistered. The theme listens and registers entry views.

Documentation

Scripts

composer test
composer analyse
composer format

License

MIT