Skip to content

Expose eg found_posts to QueryBuilder from PostQuery ? #42

@jmp909

Description

@jmp909

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions