Cách để thiết lập Post Type Archive trở thành trang chủ của website WordPress :
Bước 1 : Đầu tiên, ta và Setting -> Permalinks, chọn 1 trang bất kỳ làm trang chủ ( có thể dùng trang trắng ).
Bước 2,: Vào function.php trong theme, copy và dán đoạn code sau vào. thay thế YOUR CTP bằng tên post type của bạn ( ví dụ : portfolio, product, ... ).
/*
* 1. Go to Settings > Permalinks and select any page as home page
* 2. Then use the following code
*/
add_action( "pre_get_posts", "archive_page_as_front_page" );
function archive_page_as_front_page( $query ){
if( is_admin() ) return;
if( $query->get( 'page_id' ) == get_option( 'page_on_front' ) ){
$query->set( 'post_type', 'YOUR CTP' );
$query->set( 'page_id', '' );
$query->is_page = $query->is_singular = 0;
$query->is_archive = $query->is_post_type_archive = 1;
}
}