Skip to content

Add a return type extension for WP_Query->query() and WP_Query->get_posts() - #48

Closed
johnbillion wants to merge 2 commits into
szepeviktor:masterfrom
johnbillion:wp-query-methods
Closed

Add a return type extension for WP_Query->query() and WP_Query->get_posts()#48
johnbillion wants to merge 2 commits into
szepeviktor:masterfrom
johnbillion:wp-query-methods

Conversation

@johnbillion

Copy link
Copy Markdown
Contributor

Return type extension for WP_Query->query() and WP_Query->get_posts().

As get_posts() ultimately calls WP_Query->query() and WP_Query->get_posts(), they all share the same return type pattern. Not sure if you want to combine them somehow.

Comment on lines +43 to +45
if (count($methodCall->args) === 0) {
return new ArrayType(new IntegerType(), new ObjectType('WP_Post'));
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

https://developer.wordpress.org/reference/classes/wp_query/get_posts/ has no parameters.
The query method has one.
What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On top of that, one can also do $query = new WP_Query( $args ); $query->get_posts()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

$query = new WP_Query( $args ); $query->get_posts() will cause the database query to run twice

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, right, meant another method then. What I wanted to point out is that args can be passed to the constructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah I see, yes. I need to find some time to come back to this PR.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@johnbillion How about finishing this PR?

@johnbillion
johnbillion marked this pull request as draft October 4, 2021 16:54
@johnbillion johnbillion closed this by deleting the head repository Nov 8, 2023
@szepeviktor

Copy link
Copy Markdown
Owner

closed this by deleting the head repository

@johnbillion What about this PR?

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.

3 participants