Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 5 years ago

#24763 closed enhancement (fixed)

Add filter to query in get_page_by_path function

Reported by: zbtirrell's profile zbtirrell Owned by: johnbillion's profile 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)

get_page_by_path_request.patch (821 bytes) - added by zbtirrell 11 years ago.
patch file for the suggested change
get_page_by_path.patch (1.5 KB) - added by zbtirrell 11 years ago.
make the get_page_by_path function support an array of post types
get_page_by_path_v3.patch (1.5 KB) - added by zbtirrell 11 years ago.
a 3rd version of this patch, only adds attachment when post type is scalar
get_page_by_path_v4.patch (2.7 KB) - added by zbtirrell 11 years ago.
this patch also adds post type array support to get_page_by_title

Download all attachments as: .zip

Change History (17)

@zbtirrell
11 years ago

patch file for the suggested change

#1 @jeremyfelt
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: @zbtirrell
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 @SergeyBiryukov
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().

@zbtirrell
11 years ago

make the get_page_by_path function support an array of post types

#4 @zbtirrell
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 @SergeyBiryukov
11 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 3.9

#6 follow-up: @nacin
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?

@zbtirrell
11 years ago

a 3rd version of this patch, only adds attachment when post type is scalar

#7 in reply to: ↑ 6 @zbtirrell
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.

#8 @nacin
11 years ago

We're going to want to make the same changes to get_page_by_title() too.

@zbtirrell
11 years ago

this patch also adds post type array support to get_page_by_title

#9 @zbtirrell
11 years ago

The updated patch now contains a change to add post type array support to get_page_by_title() as requested.

#10 @johnbillion
11 years ago

  • Owner set to johnbillion
  • Resolution set to fixed
  • Status changed from new to closed

In 27423:

Allow get_page_by_path() and get_page_by_title() to accept an array of post types. Fixes #24763. Props zbtirrell.

#11 @sebastian.pisula
8 years ago

I think that filter is great idea.

#12 @Jabawack
8 years ago

Any news about a filter?

This ticket was mentioned in Slack in #core by desrosj. View the logs.


5 years ago

Note: See TracTickets for help on using tickets.