Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding query builder count() method #449

Merged
merged 1 commit into from
Sep 6, 2023
Merged

Adding query builder count() method #449

merged 1 commit into from
Sep 6, 2023

Conversation

srtfisher
Copy link
Member

@srtfisher srtfisher commented Sep 1, 2023

App\Models\Post::whereStatus( 'draft' )->count();

Copy link
Contributor

@renatonascalves renatonascalves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗡️

* @return int
*/
public function count(): int {
$this->take( -1 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sets the page limit to unlimited.

* @return bool
*/
public function exists(): bool {
return $this->count() > 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many items this WP_Query uses? I'd guess querying for 1 would be enough.

@srtfisher srtfisher merged commit db200e9 into 0.12.x Sep 6, 2023
15 checks passed
@srtfisher srtfisher deleted the query-count branch September 6, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants