Revision 176 is a pre-publication revision. (Viewing current revision instead.)

WP Admin Custom Post Type sort order

This is a function to do it easily: This might be better: http://scribu.net/wordpress/custom-sortable-columns.html [php] /*-----------------------------------------------------------------------------------*/ /* CUSTOM ORDER A CUSTOM POST TYPE IN THE WP ADMIN EDIT.PHP SCREEN */ /*---------------------------------------------------------------------*/ function posts_for_current_author($query) { if($query->is_admin) { if ($query->get('post_type') == 'articles') { $query->set('orderby', 'date'); $query->set('order', 'DESC'); } } return $query; } add_filter('pre_get_posts', 'posts_for_current_author'); [/php]

Revisions

Revision Differences

May 1, 2012 @ 01:52:58Current Revision
Content
 Added: This is a function to do it easily:
 Added: This might be better: <a href="http:// scribu.net/wordpress/custom- sortable-columns.html">http: //scribu.net/ wordpress/custom- sortable-columns.html</a>
 Added: [php]
 Added: /*----------- ------------- ------------ ------------- ------------ ----------------------*/
 Added: /* CUSTOM ORDER A CUSTOM POST TYPE IN THE WP ADMIN EDIT.PHP SCREEN */
 Added: /*----------- ------------- ------------ ------------- --------------------*/
 Added: function posts_for_current_ author($query) {
 Added: if($query-&gt;is_admin) {
 Added: if ($query-&gt;get( 'post_type') == 'articles')
 Added: {
 Added: $query-&gt;set('orderby', 'date');
 Added: $query-&gt;set('order', 'DESC');
 Added: }
 Added: }
 Added: return $query;
Deleted: Added: }
 Added: add_filter('pre_get_posts', 'posts_for_current_author');
 Added: [/php]

Note: Spaces may be added to comparison text to allow better line wrapping.

Tags: , , ,

No comments yet.

Leave a Reply