[wp-trac] [WordPress Trac] #12726: Add get_post_by_*() functions

WordPress Trac wp-trac at lists.automattic.com
Sat Mar 27 05:57:13 UTC 2010


#12726: Add get_post_by_*() functions
--------------------------+-------------------------------------------------
 Reporter:  mikeschinkel  |       Owner:               
     Type:  enhancement   |      Status:  new          
 Priority:  normal        |   Milestone:  Unassigned   
Component:  Post Types    |     Version:  3.0          
 Severity:  normal        |    Keywords:  post function
--------------------------+-------------------------------------------------
 Current there are get_page_by_path() and get_page_by_title() function but
 they hardcode the post_type of 'page'.  With support for new custom post
 types I'm finding a need for functionality to look up posts of custom post
 types:
 {{{
 $args = array('post_type','my_custom_post_type');
 $path = 'foo-bar';
 $post = get_post_by_path($path,$args);
 $title = 'Foo Bar'
 $post = get_post_by_title($title,$args);
 }}}
 Another option would be a simple get_post_by():
 {{{
 $args = array('post_type','my_custom_post_type');
 $path = 'foo-bar';
 $post = get_post_by('path',$path,$args);
 $title = 'Foo Bar'
 $post = get_post_by('title',$title,$args);
 }}}
 This code is not hard to write but looking at the functions in post.php
 there's not one consistent style so I'm not sure what the best approach
 would be to write it.  Further, I don't completely understand the
 significance of all the code in get_page_by_path() so wouldn't want to
 start with it (although I could see it being modified to use the more
 generic functions that I propose.)

 I can make these updates if I get enough direction from the core team, or
 I'd happily just see them get done. :)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12726>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list