Opened 7 years ago
Last modified 2 years 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 |
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 (17)
#1
@
7 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
@
7 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.
7 years ago
#6
@
7 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.
2 years ago
#11
@
2 years ago
- Keywords needs-dev-note added
The patch adds a new filter which will require a mention in the misc dev note.
#12
@
2 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.
Add fields_the_posts filters