Nếu bạn muốn đặt tiêu đề cho bài viết theo dạng 1. Tên tiêu đề hoặc 2. Tên tiêu đề; khi WordPress truy vấn nó sẽ xắp xếp theo dạng 1 10 rồi mới đến 2 20. Nếu bạn muốn sắp xếp theo thứ tự 1 2 3 thành 1 2 3 rồi mới đến 10 20 30 thì bạn thêm đoạn code sau vào file functions.php của giao diện:
//order numeric posts function hocwp_theme_custom_posts_orderby_filter() { global $wpdb; return sprintf( '(%s.post_title+0) ASC', $wpdb->posts ); } //order back-end posts in numeric order function hocwp_theme_custom_pre_get_posts_action( $query ) { if ( $query instanceof WP_Query && ! $query->is_main_query() ) { // Get the post type from the query $post_type = $query->get( 'post_type' ); $cat = $query->get( 'cat' ); if ( 'post' == $post_type && ! empty( $cat ) && $cat == HT_Options()->get_general( 'utilities_cat' ) ) { add_filter( 'posts_orderby', 'hocwp_theme_custom_posts_orderby_filter' ); } } } add_filter( 'pre_get_posts', 'hocwp_theme_custom_pre_get_posts_action' );
Đoạn code bên trên có dùng các hàm điều kiện, bạn cần thay đổi lại cho phù hợp với nhu cầu và mục đích của bạn nhé. Chúc thành công.