lumberjack-core
lumberjack-core copied to clipboard
Expose eg found_posts to QueryBuilder from PostQuery ?
would it be possible to expose the PostQuery
to the QueryBuilder
etc so we can get eg ->found_posts
(and any similar data)
currently I have to run a separate WP_Query
with my builder's $query->getParameters()
just to get the info again but this means querying all the posts that presumably have already been queried
I'm not sure what the syntax for it would be though. I did see it is possible to add elements to the collection outside of the items array,. so maybe accessible that way?
$social_posts = SocialPost::builder()->limit(3)->get();
$found_posts = $social_posts->found_posts;
currently I tack it on to the end of my collection from that WP_Query
then call eg
$found_posts = get_found_posts();
$social_posts->found_posts = $found_posts;
dd($social_posts);
^ Tightenco\Collect\Support\Collection {#6769 ▼
#items: array:3 [▼
0 => App\PostTypes\SocialPost {[#6565 ▶]}
1 => App\PostTypes\SocialPost {[#6564 ▶]}
2 => App\PostTypes\SocialPost {[#6561 ▶]}
]
+"found_posts": 7
}
thanks for any suggestions. J
this seems to work in the meantime
$query = (new QueryBuilder)->wherePostType(["news","event"])->limit(3)->as(SocialPost::class);
// or $query = SocialPost::builder()->limit(3);
$post_query = new PostQuery($query->getParameters(), SocialPost::class);
$posts = $post_query->get_posts();
dd(count($posts)." of ".$post_query->found_posts);
shows:
3 out of 10
is there anything that $query->get()
will give me that $post_query->get_posts()
won't? I guess some Collection
functionality? I think I can just do an equivalent with this.
$posts = collect($post_query->get_posts());
thanks