[wp-trac] [WordPress Trac] #62666: Add function to retrieve page ID or permalink based on template
WordPress Trac
noreply at wordpress.org
Mon Dec 9 02:14:30 UTC 2024
#62666: Add function to retrieve page ID or permalink based on template
-----------------------------+-----------------------------
Reporter: gustavocoimbra | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: trunk
Severity: normal | Keywords: Enhancement
Focuses: |
-----------------------------+-----------------------------
This contribution implements a new function that retrieves the ID or
permalink of a page based on its assigned template. The function performs
a query to find pages using a specific template and returns either the ID
or permalink of the first matching page.
### Details:
- The function `get_page_by_template()` accepts two parameters:
`$template` (the template name) and `$field` (which can be 'ID' for the
page ID or 'permalink' for the page URL).
- It uses `WP_Query` to search for pages with the specified template.
- The function returns either the page ID or permalink based on the
`$field` argument.
### Benefits:
- Provides an easy way to retrieve a page by its template, improving
flexibility for theme and plugin developers.
- Reduces the need for custom queries in theme files.
- Helps in dynamically linking or referencing pages based on their
template.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62666>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list