Có phải bạn muốn thiết kế website tiết kiệm chi phí và thời gian mà còn chuẩn seo ?

11/20/13

Sắp xếp post type trong admin wordpress

Mặc định bạn tạo ra 1 post type mới, danh sách các bài post sẽ sắp xếp theo 1 thứ tự mặc định (theo tiêu đề ASC). Bạn muốn tùy chỉnh việc sắp xếp này, có thể theo tiêu đề, theo ID, theo ngày

Tham khảo mẫu code dưới đâu. Code này được chèn trong file functions.php (hoặc kèm trong 1 plugin của bạn)

function set_custom_post_types_admin_order($wp_query) {
        if (is_admin()) {

            // Get the post type from the query
            $post_type = $wp_query->query['post_type'];

            if ($post_type == 'buy_a_franchise') {

                // 'orderby' value can be any column name
                //$wp_query->set('orderby', 'title');
                // 'order' value can be ASC or DESC
                $wp_query->set('order', 'DESC');
            }
        }
    }
    add_filter('pre_get_posts', 'set_custom_post_types_admin_order');

0 comments:

Post a Comment