You are viewing an old revision of this post, from May 1, 2012 @ 01:55:03. See below for differences between this version and the current revision.

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:55:03Current 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>
Deleted: [php]&lt;/pre&gt;Added: [php]
Unchanged: /*----------- ------------- ------------ ------------- ------------ ----------------------*/Unchanged: /*----------- ------------- ------------ ------------- ------------ ----------------------*/
Unchanged: /* CUSTOM ORDER A CUSTOM POST TYPE IN THE WP ADMIN EDIT.PHP SCREEN */Unchanged: /* CUSTOM ORDER A CUSTOM POST TYPE IN THE WP ADMIN EDIT.PHP SCREEN */
Unchanged: /*----------- ------------- ------------ ------------- --------------------*/Unchanged: /*----------- ------------- ------------ ------------- --------------------*/
Unchanged: function posts_for_current_ author($query) {Unchanged: function posts_for_current_ author($query) {
Unchanged: if($query-&gt;is_admin) {Unchanged: if($query-&gt;is_admin) {
Unchanged: if ($query-&gt;get( 'post_type') == 'articles')Unchanged: if ($query-&gt;get( 'post_type') == 'articles')
Unchanged: {Unchanged: {
Unchanged: $query-&gt;set('orderby', 'date');Unchanged: $query-&gt;set('orderby', 'date');
Unchanged: $query-&gt;set('order', 'DESC');Unchanged: $query-&gt;set('order', 'DESC');
Unchanged: }Unchanged: }
Unchanged: }Unchanged: }
Unchanged: return $query;Unchanged: return $query;
Unchanged: }Unchanged: }
Unchanged: add_filter('pre_get_posts', 'posts_for_current_author');Unchanged: add_filter('pre_get_posts', 'posts_for_current_author');
Deleted: &lt;pre&gt;[/php] Added: [/php]
Deleted: &nbsp; 

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

Tags: , , ,

No comments yet.

Leave a Reply