Tạo bộ tìm kiếm cho BĐS

Hướng dẫn tạo bộ tìm kiếm cho site Bất động sản WordPress P.1

Bài viết này thuộc phần 1 trong tổng số 3 bài viết trong Serie Tạo bộ tìm kiếm BĐS cho Wordpress

Về bản chất, mình chỉ cần hiểu rằng đây là tìm kiếm theo từng post type. Ví dụ trong woocommerce, post type của sản phẩm là ‘Product’ thì nay bạn có thể áp dụng tương tự phương thức tìm kiếm này.

Dưới đây là bài viết tham khảo ( mình chưa test vì không làm BĐS )

  1. Các bạn tải cài đặt wordpress tại đây
  2. Sau khi cài đặt xong, tiên hành cài plugin tạo custom post type
  3. Cài plugin Advance Custom Field ( ACF – Mình có bản pro, ai cần hãy comment cho mình share nhé )
  4. Sử dụng Custom Post Type tạo post type ‘nhà đất’, taxonomy ‘địa điểm’, và ‘loại nhà đất’. Nếu chưa biết tạo có thể copy code bên dưới bỏ vào functions.php
//post type
function cptui_register_my_cpts_nha_dat() {

  /**
   * Post Type: Nhà đất.
   */

  $labels = array(
    "name" => __( "Nhà đất", "bds" ),
    "singular_name" => __( "Nhà đất", "bds" ),
  );

  $args = array(
    "label" => __( "Nhà đất", "bds" ),
    "labels" => $labels,
    "description" => "",
    "public" => true,
    "publicly_queryable" => true,
    "show_ui" => true,
    "delete_with_user" => false,
    "show_in_rest" => true,
    "rest_base" => "",
    "rest_controller_class" => "WP_REST_Posts_Controller",
    "has_archive" => true,
    "show_in_menu" => true,
    "show_in_nav_menus" => true,
    "exclude_from_search" => false,
    "capability_type" => "post",
    "map_meta_cap" => true,
    "hierarchical" => true,
    "rewrite" => array( "slug" => "nha-dat", "with_front" => true ),
    "query_var" => true,
    "supports" => array( "title", "editor", "thumbnail", "excerpt", "revisions", "page-attributes" ),
  );

  register_post_type( "nha_dat", $args );
}

add_action( 'init', 'cptui_register_my_cpts_nha_dat' );

//taxonomy
function cptui_register_my_taxes() {

  /**
   * Taxonomy: Loại nhà đất.
   */

  $labels = array(
    "name" => __( "Loại nhà đất", "bds" ),
    "singular_name" => __( "Loại nhà đất", "bds" ),
  );

  $args = array(
    "label" => __( "Loại nhà đất", "bds" ),
    "labels" => $labels,
    "public" => true,
    "publicly_queryable => true,
    "hierarchical" => true,
    "show_ui" => true,
    "show_in_menu" => true,
    "show_in_nav_menus" => true,
    "query_var" => true,
    "rewrite" => array( 'slug' => 'loai_nha_dat', 'with_front' => true,  'hierarchical' => true, ),
    "show_admin_column" => true,
    "show_in_rest" => true,
    "rest_base" => "loai_nha_dat",
    "rest_controller_class" => "WP_REST_Terms_Controller",
    "show_in_quick_edit" => true,
    );
  register_taxonomy( "loai_nha_dat", array( "nha_dat" ), $args );

  /**
   * Taxonomy: Địa điểm.
   */

  $labels = array(
    "name" => __( "Địa điểm", "bds" ),
    "singular_name" => __( "Địa điểm", "bds" ),
  );

  $args = array(
    "label" => __( "Địa điểm", "bds" ),
    "labels" => $labels,
    "public" => true,
    "publicly_queryable => true,
    "hierarchical" => true,
    "show_ui" => true,
    "show_in_menu" => true,
    "show_in_nav_menus" => true,
    "query_var" => true,
    "rewrite" => array( 'slug' => 'dia_diem', 'with_front' => true,  'hierarchical' => true, ),
    "show_admin_column" => true,
    "show_in_rest" => true,
    "rest_base" => "dia_diem",
    "rest_controller_class" => "WP_REST_Terms_Controller",
    "show_in_quick_edit" => true,
    );
  register_taxonomy( "dia_diem", array( "nha_dat" ), $args );
}
add_action( 'init', 'cptui_register_my_taxes' );

 

5. Tạo field cho post type này ( xem hình )

Tạo field cho post type này .
Tạo field cho post type này .

6. Tạo dữ liệu cho taxonomy và post type để có dữ liệu test search bằng cách vào Admin và thêm một vài bài viết thông thường

 

Nguồn: https://blogtintonghop.com/huong-dan-tao-bo-search-bat-dong-san-wordpress-p-1/

Series NavigationHướng dẫn tạo bộ tìm kiếm cho site Bất động sản WordPress P.2 >>

Quét mã QR để đọc bài viết này để xem tiếp trên điện thoại

QR: Hướng dẫn tạo bộ tìm kiếm cho site Bất động sản WordPress P.1

2 thoughts on “Hướng dẫn tạo bộ tìm kiếm cho site Bất động sản WordPress P.1”

Leave a Comment

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *