[wp-trac] [WordPress Trac] #14019: Introduce get_id_by_name()
WordPress Trac
wp-trac at lists.automattic.com
Mon Jun 21 05:24:28 UTC 2010
#14019: Introduce get_id_by_name()
-------------------------+--------------------------------------------------
Reporter: filosofo | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 3.1
Component: Template | Version: 3.0
Severity: normal | Keywords: has-patch
-------------------------+--------------------------------------------------
Since 2.9-ish there has been an emphasis on querying objects by slug, for
various reasons (especially terms).
Unfortunately, many template functions require either that one be in the
Loop or explicitly pass a post object ID. Currently, to get an object's
ID in order to pass it to one of the functions, you have to go through
several steps that include querying the object and checking for the
necessary properties of the desired result.
'''Proposed New Function'''
int '''get_id_by_name''' ( string ''$name_or_slug'' )
Examples:
{{{
// title of the page with slug "gallery":
echo get_the_title( get_id_by_name( 'gallery' ) );
// custom field for post titled "My Day at the Beach"
echo get_post_meta( get_id_by_name( 'my-day-at-the-beach' ), 'photos-url',
true );
// images attached to the "Employees" page:
$images = get_children( array('post_parent' => get_id_by_name( 'employees'
), 'post_status' => 'inherit', 'post_type' => 'attachment',
'post_mime_type' => 'image' ) );
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14019>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list