自定义字段manage_{post_type}_posts_columns栏目文章列表排序
如果是栏目的值是数字的话,比较好用。参考下面代码
mycpt是注册的自定义文章格式,比如你注册的product或者movie就对应修改下。
Modifying the Custom Columns for a Post Type
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | add_filter( 'manage_mycpt_posts_columns', 'set_custom_edit_mycpt_columns' ); function set_custom_edit_mycpt_columns( $columns ) { $date = $colunns['date']; unset( $columns['date'] ); $columns['photo'] = __( 'Photo', 'my-text-domain' ); $columns['custom_taxonomy'] = __( 'Custom Taxonomy', 'my-text-domain' ); $columns['acf_field'] = __( 'ACF Field', 'my-text-domain' ); $columns['date'] = $date; return $columns; } |
Adding Data to the New Columns
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | add_filter( 'manage_mycpt_posts_columns', 'set_custom_edit_mycpt_columns' ); function set_custom_edit_mycpt_columns( $columns ) { $date = $colunns['date']; unset( $columns['date'] ); $columns['photo'] = __( 'Photo', 'my-text-domain' ); $columns['custom_taxonomy'] = __( 'Custom Taxonomy', 'my-text-domain' ); $columns['acf_field'] = __( 'ACF Field', 'my-text-domain' ); $columns['date'] = $date; return $columns; } |
Adding Data to the New Columns
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | add_action( 'manage_mycpt_posts_custom_column' , 'custom_mycpt_column', 10, 2 ); function custom_mycpt_column( $column, $post_id ) { switch ( $column ) { // display a thumbnail photo case 'photo' : echo get_the_post_thumbnail( $post_id, 'thumbnail' ); break; // display a list of the custom taxonomy terms assigned to the post case 'custom_taxonomy' : $terms = get_the_term_list( $post_id , 'my_custom_taxonomy' , '' , ', ' , '' ); echo is_string( $terms ) ? $terms : '—'; break; // display the value of an ACF (Advanced Custom Fields) field case 'acf_field' : echo get_field( 'my_acf_field', $post_id ); break; } } |
参考:https://www.ractoon.com/wordpress-sortable-admin-columns-for-custom-posts/