#24763 closed enhancement (fixed)
Add filter to query in get_page_by_path function
Reported by: | zbtirrell | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.6 |
Component: | Posts, Post Types | Keywords: | has-patch |
Focuses: | Cc: |
Description
We would like to be able to filter the query that is executed in get_page_by_path() so that we can have pages be children of a custom post_type.
To do this currently, we have to add a filter to 'query' and look for this specific query. This approach is unfortunately, quite expensive.
I am attaching a single line diff file that applies a filter to this query called 'get_page_by_path_request'.
Attachments (4)
Change History (17)
#1
@
11 years ago
- Keywords reporter-feedback added
Hi @zbtirrell, thanks for the request and patch.
What alternative queries do you visualize using through this filter? I don't think we would want to apply a filter directly to the query itself. It is worth discussing what else could be added to help achieve your goal.
#2
follow-up:
↓ 3
@
11 years ago
We are specifically interested in adding additional post types, so this is the part that we are most interested in having the filter change:
(post_type = '$post_type_sql' OR post_type = 'attachment')
Perhaps we could allow for $post_types to be an array that gets imploded to build this segment?
#3
in reply to:
↑ 2
@
11 years ago
- Keywords needs-patch added; reporter-feedback removed
Replying to zbtirrell:
Perhaps we could allow for $post_types to be an array that gets imploded to build this segment?
This seems like the way to go here. Let's do it for both get_page_by_path()
and get_page_by_title()
.
#4
@
11 years ago
I did not make a patch for get_page_by_title()
because it does not suffer from the same difficulty. Since it simply does a query on title and post type, it does not consider the page's hierarchy/ancestry, so is not broken if a page has an parent that is not a page.
So, while extending that function to support an array would potentially be useful, it seems out of scope from this request.
Note: I tested the patch against trunk.
#5
@
11 years ago
- Keywords has-patch added; needs-patch removed
- Milestone changed from Awaiting Review to 3.9
#6
follow-up:
↓ 7
@
11 years ago
We could choose to only add 'attachment' if you're passing a scalar value. If you pass an array, then it's an explicit list and attachments are ignored. Thoughts?
#7
in reply to:
↑ 6
@
11 years ago
Replying to nacin:
We could choose to only add 'attachment' if you're passing a scalar value. If you pass an array, then it's an explicit list and attachments are ignored. Thoughts?
Seems like a great idea, updated patch has been uploaded.
#9
@
11 years ago
The updated patch now contains a change to add post type array support to get_page_by_title() as requested.
#10
@
11 years ago
- Owner set to johnbillion
- Resolution set to fixed
- Status changed from new to closed
In 27423:
patch file for the suggested change