Make WordPress Core

Opened 9 years ago

Closed 8 years ago

#36465 closed feature request (wontfix)

Implement get_content_id_by_slug() function

Reported by: eclare's profile eclare Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: administration, template Cc:

Description

Sometimes theme & plugin creators have a need to get the ID of any content type (usually a page) by its slug. Aside from use cases where developers prefer to hardcode slugs rather than IDs themselves (which seems better), this could also be used to detect and set some default values, for example: finding the contact page (slug: contact, contact-us, contact-2), home page etc...

This currently requires a few lines of code, posted here: https://gist.github.com/eddt/ee1018f26f8fc195629a (not sure if it would work with child theme slugs without parent slugs).

This could be in the core as get_content_id_by_slug() or similarly named function.

Change History (1)

#1 @swissspidy
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

get_page_by_path() returns the post object or null on failure. The function in the gist uses get_page_by_path() to return the post ID or null on failure. That's not really an improvement as you'd still have to check against null in your code.

I'm closing this since get_page_by_path() works just fine and there's been no activity in almost a year.

Note: See TracTickets for help on using tickets.