[wp-trac] [WordPress Trac] #57622: Add filter to get_page_by_path

WordPress Trac noreply at wordpress.org
Thu Jul 18 22:57:43 UTC 2024


#57622: Add filter to get_page_by_path
-------------------------------+------------------------------
 Reporter:  uzumymw            |       Owner:  (none)
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:
 Severity:  normal             |  Resolution:
 Keywords:  has-patch          |     Focuses:
-------------------------------+------------------------------

Comment (by xipasduarte):

 Hello @uzumymw. I've taken a stab at this and provided a different version
 with a couple of hooks. I found your ticket based on a need I encountered
 where I wanted to keep the same `post_name` for two posts, but
 differentiate then by another property (language, for example). Due to the
 usage of this function we were not able to make it work without a bunch of
 hooks and corrections to the returning ID.

 The hooks that I propose are:

 - `page_by_path_id` filters the found ID to something that the user
 believes is the desired result.
 - `page_by_path_cache_key` adds the ability to control the cache key,
 which allows for scenarios where the same perceived path is actually a
 reference for two, or more, posts, based on something else.

 I didn't add the `$last_changed` value, because its current effect will
 bust all caches when the `'posts'` cache group is updated. I feel we might
 want to keep this in the resulting value, even after filtering, so as to
 prevent caching issues, but I'd differ to others better equipped to answer
 this.

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


More information about the wp-trac mailing list