Add a return type extension for WP_Query->query() and WP_Query->get_posts() - #48
Add a return type extension for WP_Query->query() and WP_Query->get_posts()#48johnbillion wants to merge 2 commits into
WP_Query->query() and WP_Query->get_posts()#48Conversation
| if (count($methodCall->args) === 0) { | ||
| return new ArrayType(new IntegerType(), new ObjectType('WP_Post')); | ||
| } |
There was a problem hiding this comment.
https://developer.wordpress.org/reference/classes/wp_query/get_posts/ has no parameters.
The query method has one.
What do you think?
There was a problem hiding this comment.
On top of that, one can also do $query = new WP_Query( $args ); $query->get_posts()
There was a problem hiding this comment.
$query = new WP_Query( $args ); $query->get_posts() will cause the database query to run twice
There was a problem hiding this comment.
Ah, right, meant another method then. What I wanted to point out is that args can be passed to the constructor.
There was a problem hiding this comment.
Ah I see, yes. I need to find some time to come back to this PR.
@johnbillion What about this PR? |
Return type extension for
WP_Query->query()andWP_Query->get_posts().As
get_posts()ultimately callsWP_Query->query()andWP_Query->get_posts(), they all share the same return type pattern. Not sure if you want to combine them somehow.