Oh oh! Page not found.
We're sorry, but the page you are looking for doesn't exist. You can search your topic using the box below or return to the homepage.
Back to Homepage// PROPERTY CUSTOM POST TYPE FOR SEO
function register_property_post_type() {
$labels = array(
'name' => 'Properties',
'singular_name' => 'Property',
'menu_name' => 'Properties',
'add_new' => 'Add New Property',
'add_new_item' => 'Add New Property',
'edit_item' => 'Edit Property',
'new_item' => 'New Property',
'view_item' => 'View Property',
'search_items' => 'Search Properties',
'not_found' => 'No properties found',
'not_found_in_trash' => 'No properties found in trash',
);
$args = array(
'labels' => $labels,
'public' => true, // SEO CRITICAL: Makes posts visible to search engines
'publicly_queryable' => true, // SEO CRITICAL: Allows individual property pages
'show_ui' => true, // Shows in WordPress admin
'show_in_menu' => true, // Shows in admin menu
'query_var' => true,
'rewrite' => array('slug' => 'property'), // SEO-friendly URLs: /property/property-name/
'capability_type' => 'post',
'has_archive' => true, // SEO CRITICAL: Creates /property/ archive page
'hierarchical' => false,
'menu_position' => 5,
'menu_icon' => 'dashicons-building',
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'),
'show_in_rest' => true, // Enables Gutenberg editor
'taxonomies' => array('property_type', 'district'), // For RankMath categorization
);
register_post_type('property', $args);
}
add_action('init', 'register_property_post_type');
// PROPERTY TAXONOMIES FOR SEO CATEGORIZATION
function register_property_taxonomies() {
// Property Type taxonomy (Sale/Rent/etc)
register_taxonomy('property_type', 'property', array(
'labels' => array(
'name' => 'Property Types',
'singular_name' => 'Property Type',
),
'public' => true,
'hierarchical' => true,
'rewrite' => array('slug' => 'type'),
'show_in_rest' => true,
));
// District taxonomy for location-based SEO
register_taxonomy('district', 'property', array(
'labels' => array(
'name' => 'Districts',
'singular_name' => 'District',
),
'public' => true,
'hierarchical' => true,
'rewrite' => array('slug' => 'district'),
'show_in_rest' => true,
));
}
add_action('init', 'register_property_taxonomies');
// COMPLETE the function you started
function update_all_property_posts_to_published() {
$args = array(
'post_type' => 'property',
'post_status' => 'draft',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'property_number',
'compare' => 'EXISTS'
)
)
);
$properties = get_posts($args);
foreach($properties as $property) {
wp_update_post(array(
'ID' => $property->ID,
'post_status' => 'publish' // SEO CRITICAL: Makes posts visible to search engines
));
echo "Published property: " . $property->post_title . "
";
}
echo "Updated " . count($properties) . " properties to published status.";
}
// PROPERTY CUSTOM POST TYPE FOR SEO
function register_property_post_type() {
$labels = array(
'name' => 'Properties',
'singular_name' => 'Property',
'menu_name' => 'Properties',
'add_new' => 'Add New Property',
'add_new_item' => 'Add New Property',
'edit_item' => 'Edit Property',
'new_item' => 'New Property',
'view_item' => 'View Property',
'search_items' => 'Search Properties',
'not_found' => 'No properties found',
'not_found_in_trash' => 'No properties found in trash'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_rest' => true, // For Gutenberg editor
'query_var' => true,
'rewrite' => array('slug' => 'property', 'with_front' => false),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 5,
'menu_icon' => 'dashicons-building',
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'custom-fields'),
'show_in_nav_menus' => true,
'can_export' => true,
'exclude_from_search' => false // IMPORTANT FOR SEO!
);
register_post_type('property', $args);
}
add_action('init', 'register_property_post_type');
// CREATE PROPERTY POSTS FROM DATABASE FOR SEO
function sync_properties_to_posts($limit = 50) {
global $wpdb;
// Get properties that don't have posts yet
$properties = $wpdb->get_results("
SELECT u.*, e.E_ESTATE, e.C_ESTATE, d.E_DISTRICT, d.C_DISTRICT
FROM UPLOADPROP u
LEFT JOIN ESTATE e ON u.ESTATE = e.ESTATE
LEFT JOIN DISTRICT d ON u.DISTRICT = d.DISTRICT
LEFT JOIN {$wpdb->posts} p ON p.post_name = CONCAT('property-', u.NUMBER)
WHERE p.ID IS NULL
AND u.DELETEDATE = 0
AND u.STATUS IN ('Available', 'available', 'AVAILABLE')
LIMIT $limit
");
$created_count = 0;
foreach ($properties as $property) {
// Create SEO-friendly title
$title = create_property_title($property);
// Create SEO-friendly content
$content = create_property_content($property);
// Create SEO-friendly excerpt
$excerpt = create_property_excerpt($property);
// Create the post
$post_data = array(
'post_title' => $title,
'post_content' => $content,
'post_excerpt' => $excerpt,
'post_status' => 'publish',
'post_type' => 'property',
'post_name' => 'property-' . $property->NUMBER, // SEO-friendly URL
'meta_input' => array(
'property_number' => $property->NUMBER,
'property_price' => $property->PRICE,
'property_rent' => $property->RENT,
'property_area' => $property->GROSSAREA,
'property_type' => $property->E_PROPTYPE,
'property_district' => $property->E_DISTRICT,
'property_estate' => $property->E_ESTATE,
'property_building' => $property->E_BUILDING,
'property_bedrooms' => $property->BEDROOM,
'property_bathrooms' => $property->BATHROOM,
'property_floor' => $property->FLOOR,
'property_unit' => $property->UNIT
)
);
$post_id = wp_insert_post($post_data);
if (!is_wp_error($post_id)) {
$created_count++;
// Set property category taxonomy if needed
wp_set_object_terms($post_id, array($property->E_PROPTYPE), 'property_type');
wp_set_object_terms($post_id, array($property->E_DISTRICT), 'property_location');
}
}
return $created_count;
}
// CREATE SEO-FRIENDLY PROPERTY TITLE
function create_property_title($property) {
$parts = array();
// Property type
if (!empty($property->E_PROPTYPE)) {
$parts[] = $property->E_PROPTYPE;
}
// Bedrooms
if (!empty($property->BEDROOM) && $property->BEDROOM > 0) {
$parts[] = $property->BEDROOM . ' Bedroom';
}
// Area
if (!empty($property->GROSSAREA) && $property->GROSSAREA > 0) {
$parts[] = number_format($property->GROSSAREA) . ' sq ft';
}
// Location
if (!empty($property->E_ESTATE)) {
$parts[] = 'in ' . $property->E_ESTATE;
} elseif (!empty($property->E_DISTRICT)) {
$parts[] = 'in ' . $property->E_DISTRICT;
}
// Action type
$action = (!empty($property->RENT) && $property->RENT > 0) ? 'for Rent' : 'for Sale';
$parts[] = $action;
return implode(' ', $parts);
}
// CREATE SEO-FRIENDLY PROPERTY CONTENT
function create_property_content($property) {
$content = '
This beautiful ' . strtolower($property->E_PROPTYPE) . ' is located in the prime area of ' . $property->E_DISTRICT . ', Hong Kong.
'; // Key features $content .= 'Sale Price: HK$' . number_format($property->PRICE) . '
'; } if (!empty($property->RENT) && $property->RENT > 0) { $content .= 'Monthly Rent: HK$' . number_format($property->RENT) . '
'; } // Location details $content .= 'District: ' . $property->E_DISTRICT . '
'; if (!empty($property->E_ESTATE)) { $content .= 'Estate: ' . $property->E_ESTATE . '
'; } if (!empty($property->E_BUILDING)) { $content .= 'Building: ' . $property->E_BUILDING . '
'; } // Additional remarks if (!empty($property->E_REMARKS)) { $content .= '' . $property->E_REMARKS . '
'; } $content .= 'Created ' . $count . ' property posts!
This will create WordPress posts from your property database for SEO optimization.
'; echo ''; echo 'We're sorry, but the page you are looking for doesn't exist. You can search your topic using the box below or return to the homepage.
Back to Homepage