Opened 8 years ago
Last modified 3 months ago
#35476 accepted enhancement
Allow posts to be filtered before return when `fields` parameter is used with `WP_Query`
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Query | Keywords: | dev-feedback has-patch has-unit-tests needs-dev-note reporter-feedback needs-refresh close |
Focuses: | Cc: |
Description
Right now, when the fields parameter is used with WP_Query ("ids" or "id=>parent"), the returned posts are not filterable at all. Later in WP_Query, the_posts can be used to filter returned posts. This functionality should be mimicked with fields queries.
The use case for this is in plugins that bypass MySQL in WP Query (Elasticsearch). Fields queries right now can not be bypassed.
Patch attached.
Attachments (5)
Change History (18)
#1
@
8 years ago
- Keywords dev-feedback has-patch needs-unit-tests needs-docs added
This seems super useful, thanks!
When I installed the patch I got this error (twice) when running phpunit:
PHP Fatal error: Call-time pass-by-reference has been removed...
(L 3534 & 3534) - looking at the other filters, the ones passing $this by reference all use apply_filters_ref_array
#4
@
8 years ago
- Keywords needs-docs removed
- Add docblocks for the new hook
- Regenerate from trunk folder
This ticket was mentioned in Slack in #core by welcher. View the logs.
8 years ago
#6
@
8 years ago
35476.2.diff is a more concise patch: if the filter returns anything but false we return that, otherwise behavior is unchanged. Also, the test_query_fields_integers
test now passes.
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
3 years ago
#11
@
3 years ago
- Keywords needs-dev-note added
The patch adds a new filter which will require a mention in the misc dev note.
#12
@
3 years ago
- Keywords reporter-feedback needs-refresh added
- Milestone changed from 5.7 to Awaiting Review
@welcher or @tlovett1 - is this filter still needed? Since we added posts_pre_query
in WP4.6, plugins like Elasticpress can filter even fields
queries effectively as far as I can tell.
Can you let me know if this is still needed?
- If so, it looks like the code needs to get moved to
src/wp-includes/class-wp-query.php
now (and I guess tests would move as well). - If not, let's closed this ticket.
#13
@
3 months ago
- Keywords close added
@adamsilverstein I confirmed with @felipeelia thatEP uses the posts_pre_query
filter (see: https://github.com/10up/ElasticPress/blob/dc6a2ea675d0fd992ac8a482df718db47d3b9ac3/includes/classes/Indexable/Post/QueryIntegration.php#L64C49-L64C61 in the get_es_posts
method we do check for fields and that is working fine). As such, we can probably close this as wontfix
?
Add fields_the_posts filters