Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Ahondev/portfolio-v2/llms.txt
Use this file to discover all available pages before exploring further.
EloquentCPT is WP SSR’s thin ORM layer that maps WordPress posts and their ACF fields into plain PHP objects. Instead of wrangling WP_Query arrays directly, you call expressive static methods like Article::query()->orderBy('date', DESC)->limit(6)->get() and receive a Laravel Collection of strongly-typed model instances. The QueryBuilder fluent builder translates each chained call into the correct WP_Query arguments before executing.
Defining a Model
Every post type gets one PHP class inapp/PostTypes/. The only required member is the static $model string that maps the class to a WordPress post type slug.
Model files are generated automatically by
EloquentManager::generate(). You rarely need to write them by hand unless you want to add custom instance methods.Constructor Behaviour
WP_Post object is passed, the constructor maps these core properties directly from WP_Post:
| Property | Source |
|---|---|
$id | $post->ID |
$type | $post->post_type |
$title | $post->post_title |
$slug | $post->post_name |
$date | $post->post_date |
$excerpt | $post->post_excerpt |
The
$content and $thumbnail properties are declared on the class but are not populated from WP_Post in the constructor. They are only set if a corresponding ACF field named content or thumbnail exists and is returned by get_fields().initACFFields() is called. It calls get_fields($this->id) and iterates over every ACF field returned, assigning each value as a dynamic property on the instance. This means all your registered ACF fields — including nested Repeater arrays — become first-class properties.
Static Methods
EloquentCPT::query()
Returns a QueryBuilder scoped to the calling class’s $model post type. Uses late static binding so subclasses get the correct model automatically.
EloquentCPT::queryTerms()
Fetches taxonomy terms and returns a clean array of {id, name, slug} objects, automatically excluding the WordPress default “Non classé” / “uncategorized” term.
The taxonomy slug to query, e.g.
'category'.When
true, terms with zero associated posts are excluded. Defaults to false.Instance Methods
toArray()
Returns all public properties of the model as an associative array, equivalent to get_object_vars($this).
ApiController:
QueryBuilder
QueryBuilder is constructed internally by EloquentCPT::query(). Chain as many methods as you need before calling get() or all() to execute the query.
all()
Fetches every post with no limit (sets posts_per_page = -1).
limit()
Sets the maximum number of posts to return.
offset()
Skips the first $offset posts. Useful for manual pagination.
orderBy()
The WP_Query
orderby field, e.g. 'date', 'title', 'menu_order', 'meta_value'.Either
ASC or DESC. The constants Ahon\WPCMS\Eloquent\ASC and DESC are exported from the namespace.random()
Returns $limit posts in random order (sets orderby = 'rand').
search()
Performs a WordPress keyword search (WP_Query 's' parameter). The query string is sanitised with sanitize_text_field().
matchIds()
Restricts results to a specific list of post IDs. Results are returned in the order of the provided array.
matchSlugs()
Restricts results to a specific list of post slugs. Each slug is sanitised with sanitize_title(). Results are returned in slug-array order.
where()
Adds an ACF meta_query condition. If $value is omitted, the operator defaults to =.
The ACF field name / meta key.
Comparison operator:
=, !=, >, >=, <, <=, LIKE, NOT LIKE, IN, NOT IN, BETWEEN, NOT BETWEEN.The value to compare against. When omitted,
$operator is treated as the value and = is used.orWhere() / andWhere()
Identical to where() but set the meta query relation to OR or AND respectively. The default relation is AND.
taxonomy()
Filter posts by taxonomy term. Pass '*' as $term to skip the filter entirely (useful for conditional logic).
The taxonomy slug. Calls
wp_die() if the taxonomy does not exist.A single term slug, an array of term slugs, or
'*' to match all.with()
Eager-load taxonomy terms onto each result post. Uses a single optimised SQL query per taxonomy instead of N+1 calls.
Currently only
'taxonomy' is supported.One or more taxonomy slugs to eager-load. Each is validated with
taxonomy_exists().get()
Executes the WP_Query, hydrates each post as an EloquentCPT subclass instance, performs any eager-loaded taxonomy lookups, and returns an Illuminate Collection.
Full Query Examples
EloquentManager
EloquentManager is the internal registry that tracks which slug maps to which class name. You do not interact with it directly — PostType::create() calls EloquentManager::__add() automatically.
EloquentManager::generate()
Generates PHP class files in app/PostTypes/ for every registered post type. It also regenerates the Post model for the built-in WordPress post type.