如何通过自定义字段
-
-
这是另一个有用的答案,可以按....
对帖子进行排序 ** http://wordpress.stackexchange.com/questions/66455/how-to-change-order-of-posts-in-admin**Here another useful answer, to sort posts by ....
**http://wordpress.stackexchange.com/questions/66455/how-to-change-order-of-posts-in-admin**- 1
- 2014-05-22
- T.Todua
-
2 个回答
- 投票数
-
- 2010-12-12
从WordPress 3.1(我正在使用Beta版)开始,列现在可以通过标题进行排序.
以下文章详细介绍了如何实现它们.
As of WordPress 3.1 (I'm using the beta) columns can now be sortable via their titles.
The following post details how implement them.
-
- 2016-05-16
这是一个简单的解决方案:
/* --------Sortable Events on Dashboard - show start date, time, venue--------- */ /*------------------------------------------------------------------------------- Custom Columns -------------------------------------------------------------------------------*/ function my_*YOUR POST TYPE*_columns($columns) { $columns = array( 'cb' => '<input type="checkbox" />', 'title' => 'Title', 'your_custom_field' => 'Custom Field Name', 'date' => 'Date', ); return $columns; } function my_custom_columns($column) { global $post; if($column == 'your_custom_field') { if(get_post_meta($post->ID, 'your_custom_field', true);) { echo get_post_meta($post->ID, 'your_custom_field', true); } } } add_action("manage_posts_custom_column", "my_custom_columns"); add_filter("manage_edit-*YOUR POST TYPE*_columns", "my_events_columns"); /*------------------------------------------------------------------------------- Sortable Columns -------------------------------------------------------------------------------*/ function my_column_register_sortable( $columns ) { $columns['your_custom_field'] = 'your_custom_field'; return $columns; } add_filter("manage_edit-*YOUR POST TYPE*_sortable_columns", "my_column_register_sortable" );
只需替换 您的邮寄类型 和"您的自定义字段"
Here's a simple solution:
/* --------Sortable Events on Dashboard - show start date, time, venue--------- */ /*------------------------------------------------------------------------------- Custom Columns -------------------------------------------------------------------------------*/ function my_*YOUR POST TYPE*_columns($columns) { $columns = array( 'cb' => '<input type="checkbox" />', 'title' => 'Title', 'your_custom_field' => 'Custom Field Name', 'date' => 'Date', ); return $columns; } function my_custom_columns($column) { global $post; if($column == 'your_custom_field') { if(get_post_meta($post->ID, 'your_custom_field', true);) { echo get_post_meta($post->ID, 'your_custom_field', true); } } } add_action("manage_posts_custom_column", "my_custom_columns"); add_filter("manage_edit-*YOUR POST TYPE*_columns", "my_events_columns"); /*------------------------------------------------------------------------------- Sortable Columns -------------------------------------------------------------------------------*/ function my_column_register_sortable( $columns ) { $columns['your_custom_field'] = 'your_custom_field'; return $columns; } add_filter("manage_edit-*YOUR POST TYPE*_sortable_columns", "my_column_register_sortable" );
Just replace YOUR POST TYPE and 'your_custom_field'
在编辑我的一种自定义帖子类型时,我希望能够通过一个自定义字段列出所有条目,而不是它们的发布日期(对于自定义帖子类型而言,这可能是不相关的).我从有关自定义帖子类型的博客帖子的评论中获得线索,作者说这是可能的,甚至他做到了,因此您可以单击列名称进行自定义排序.他提到了
的解决方案posts_orderby
函数,但我现在可以在其中找到它了博客文章了.有什么建议?我看到了一种使用check_page
函数使用add_filter
来更改查询,但我很确定它只能在主题文件中使用,而不能在管理区域中使用.