sleak / query
WordPress post and term entities, query builders, and flat registration discovery for the Sleak theme.
Requires
- php: ^8.3
- illuminate/pagination: ^13.0
- illuminate/support: ^13.0
- roots/acorn: ^6.0
- sleak/support: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.29
- orchestra/testbench: ^11.0
- pestphp/pest: ^4.4
- yoast/phpunit-polyfills: ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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