[wp-trac] [WordPress Trac] #32275: get_page_by_title could return an array with all the matches

WordPress Trac noreply at wordpress.org
Thu May 7 12:56:57 UTC 2015


#32275: get_page_by_title could return an array with all the matches
-------------------------+------------------------------
 Reporter:  brgweb       |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Query        |     Version:  4.2.1
 Severity:  normal       |  Resolution:
 Keywords:  close        |     Focuses:  template
-------------------------+------------------------------
Changes (by boonebgorges):

 * keywords:   => close


Comment:

 The ability to pass an array of post types to this function was added in
 #24763 [27423].

 We can't change simply change the function to return an array of found
 posts rather than a single post. This change would break backward
 compatibility for all plugins using the function. We could possibly
 introduce a `$single` parameter, like `get_metadata()` has; the default,
 `true`, would return the first matched post, while `false` would return an
 array of matched posts.

 `get_page_by_title()` seems to me like a poor workaround for the fact that
 `WP_Query` doesn't allow queries by 'post_title'. I'm assuming this was
 never implemented because of performance concerns - the `post_title`
 column in the posts table is not indexed. That being said, it seems like a
 better use of effort to work toward 'post_title' support in `WP_Query`
 than to continue to make `get_page_by_title()` into an all-purpose
 function. (It's worth noting that `get_page_by_title()` is not used in WP
 core.)

 A side note: much the same could be said about `get_page_by_path()`,
 though that function does have a special purpose: it can parse a
 `complex/path/with/slashes` and turn it into a `'post_name'`. Since
 [30158] #18962, it's possible for posts in different post types to share
 the same 'post_name'.

 I'm suggesting that we close as wontfix, but happy to hear other points of
 view.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32275#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list