[wp-trac] [WordPress Trac] #13229: Search Custom Post Type in Media Library

WordPress Trac wp-trac at lists.automattic.com
Mon May 24 17:31:40 UTC 2010


#13229: Search Custom Post Type in Media Library
-------------------------+--------------------------------------------------
 Reporter:  lucaskeiser  |       Owner:           
     Type:  enhancement  |      Status:  new      
 Priority:  normal       |   Milestone:  3.0      
Component:  Post Types   |     Version:  3.0      
 Severity:  normal       |    Keywords:  has-patch
-------------------------+--------------------------------------------------

Comment(by t31os_):

 Shouldn't this be pulling the post type object to ascertain what the
 relevant labels are? Like has been done in edit.php for dealing with the
 various post type labels.

 Post types can register these labels already, so it's a matter of updating
 the media files (amongst other areas) to be updated inline with the method
 used in edit.php, use the relevant post type's label(s) array to determine
 what should be displayed.

 Example registered post type with appropriate labels registered, follows
 the same style as those set for posts (have left out other parameters,
 this is for illustration only).

 {{{
 register_post_type( 'book', array(
         'labels' => array(
                 'name' => 'Books',
                 'singular_name' => 'Book',
                 'add_new' => 'Add New',
                 'add_new_item' => 'Add New Book',
                 'edit_item' => 'Edit book',
                 'edit' => 'Edit',
                 'new_item' => 'New Book',
                 'view_item' => 'View Book',
                 'search_items' => 'Search Books',
                 'not_found' => 'No books found',
                 'not_found_in_trash' => 'No books found in Trash',
                 'view' => 'View Book'
         )
 ) );
 }}}

 Additionally i don't think you need that extra "attachment" parameter, if
 you leave the existing radio buttons in place and do a seperate foreach
 over get_post_types like so, you'll not need the new parameter..

 {{{
                                 <input type="radio" name="find-posts-what"
 id="find-posts-posts" checked="checked" value="posts" />
                                 <label for="find-posts-posts"><?php _e(
 'Posts' ); ?></label>
                                 <input type="radio" name="find-posts-what"
 id="find-posts-pages" value="pages" />
                                 <label for="find-posts-pages"><?php _e(
 'Pages' ); ?></label>
                         <?php
                         $selected = 'checked="checked" ';
                         $post_types = get_post_types( array( '_builtin' =>
 false ) , 'objects' );

                         foreach ($post_types AS $post) {
                                 if( post_type_supports( $post->name ,
 'editor' ) ) {
                                 ?>
                                 <input type="radio" name="find-posts-what"
 id="find-posts-<?php echo $post->name; ?>" value="<?php echo $post->name;
 ?>" <?php echo $selected?>/>
                                 <label for="find-posts-<?php echo
 $post->name; ?>"><?php echo $post->label; ?></label>
                                 <?php
                                 $selected = '';
                                 }
                         }
                         ?>
 }}}

 Again for illustration, the above should probably fetch the labels from
 the post type object, but i borrowed the code from the patch so i could be
 quick and give a simple illustration (i had the code there already).

 You guys replied whilst i was looking at this. I also had to apply the
 patch by hand, not working. If the post type supports the editor, it
 supports attachments right? I figured it seemed like the obvious choice
 for above..

 Didn't look at the JS, but i'm sure it's trivial compared with the other
 suggested changes.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/13229#comment:8>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list