Hi Roots,
We’re working with Radicle 2 and using Illuminate\Database\Eloquent\Model alongside WordPress.
I have a few questions / concerns about how this integrates with WordPress internals (WP_Query($args)), especially in when extending the query $args. For example in combination with pagination or with plugins like FacetWP.
(1.) WP_Query integration with Eloquent models
Is it possible (or intended) to integrate Eloquent model queries with WP_Query arguments?
An Eloquent model is not related to WP_Query by default. In order to opt in to WordPress core functionality such as pagination or WP_Query-style arguments, we currently handle it like this:
class Employee extends Model
{
public static function byTermId(int $termId, ?string $taxonomy = null, int $limit = -1): Collection
{
if (empty($taxonomy)) {
return collect();
}
$postIds = get_posts([
'post_type' => 'employee',
'post_status' => 'publish',
'posts_per_page' => $limit,
'fields' => 'ids',
'facetwp' => true,
'tax_query' => [
[
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => $termId,
],
],
]);
if (empty($postIds)) {
return collect();
}
return static::query()->whereIn('ID', $postIds)->get();
}
}
Ideally, we would like to express this kind of query more naturally alongside the model itself, instead of splitting logic between get_posts() / WP_Query and Eloquent.
Is this something that is intended or recommended within Radicle? Or is there a known limitation / best practice / design pattern when comparing or combining these two approaches?
(2) Query caching for Eloquent models
Is there any built-in support for caching Eloquent model queries in this setup, or is caching expected to be handled separately (e.g. WordPress object cache, transients, or a custom caching layer)?
Is this something that is intended or recommended within Radicle? Or is there a known limitation / best practice / design pattern?
Any guidance or best practices on how to structure this cleanly in Radicle 2 would be greatly appreciated.
Looking forward to your insights.
Best regards,
Lex