Step 2.2: Register Property taxonomies (type, status, location) with default terms

This commit is contained in:
Hanson.xyz Dev
2025-11-28 16:31:35 -06:00
parent d76391a457
commit f03dea6b07
2 changed files with 133 additions and 7 deletions
File diff suppressed because one or more lines are too long
@@ -62,6 +62,132 @@ function homeproz_register_property_cpt() {
}
add_action('init', 'homeproz_register_property_cpt');
/**
* Register Property Taxonomies
*/
function homeproz_register_property_taxonomies() {
// Property Type (Residential, Commercial, Land, Multi-Family)
$type_labels = array(
'name' => _x('Property Types', 'Taxonomy general name', 'homeproz'),
'singular_name' => _x('Property Type', 'Taxonomy singular name', 'homeproz'),
'search_items' => __('Search Property Types', 'homeproz'),
'popular_items' => __('Popular Property Types', 'homeproz'),
'all_items' => __('All Property Types', 'homeproz'),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __('Edit Property Type', 'homeproz'),
'update_item' => __('Update Property Type', 'homeproz'),
'add_new_item' => __('Add New Property Type', 'homeproz'),
'new_item_name' => __('New Property Type Name', 'homeproz'),
'separate_items_with_commas' => __('Separate property types with commas', 'homeproz'),
'add_or_remove_items' => __('Add or remove property types', 'homeproz'),
'choose_from_most_used' => __('Choose from the most used property types', 'homeproz'),
'not_found' => __('No property types found.', 'homeproz'),
'menu_name' => __('Property Types', 'homeproz'),
);
register_taxonomy('property_type', array('property'), array(
'hierarchical' => true,
'labels' => $type_labels,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'property-type'),
));
// Property Status (Active, Pending, Sold)
$status_labels = array(
'name' => _x('Property Status', 'Taxonomy general name', 'homeproz'),
'singular_name' => _x('Property Status', 'Taxonomy singular name', 'homeproz'),
'search_items' => __('Search Property Statuses', 'homeproz'),
'popular_items' => __('Popular Property Statuses', 'homeproz'),
'all_items' => __('All Property Statuses', 'homeproz'),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __('Edit Property Status', 'homeproz'),
'update_item' => __('Update Property Status', 'homeproz'),
'add_new_item' => __('Add New Property Status', 'homeproz'),
'new_item_name' => __('New Property Status Name', 'homeproz'),
'separate_items_with_commas' => __('Separate statuses with commas', 'homeproz'),
'add_or_remove_items' => __('Add or remove statuses', 'homeproz'),
'choose_from_most_used' => __('Choose from the most used statuses', 'homeproz'),
'not_found' => __('No statuses found.', 'homeproz'),
'menu_name' => __('Status', 'homeproz'),
);
register_taxonomy('property_status', array('property'), array(
'hierarchical' => true,
'labels' => $status_labels,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'property-status'),
));
// Property Location (Cities/Areas)
$location_labels = array(
'name' => _x('Locations', 'Taxonomy general name', 'homeproz'),
'singular_name' => _x('Location', 'Taxonomy singular name', 'homeproz'),
'search_items' => __('Search Locations', 'homeproz'),
'popular_items' => __('Popular Locations', 'homeproz'),
'all_items' => __('All Locations', 'homeproz'),
'parent_item' => __('Parent Location', 'homeproz'),
'parent_item_colon' => __('Parent Location:', 'homeproz'),
'edit_item' => __('Edit Location', 'homeproz'),
'update_item' => __('Update Location', 'homeproz'),
'add_new_item' => __('Add New Location', 'homeproz'),
'new_item_name' => __('New Location Name', 'homeproz'),
'separate_items_with_commas' => __('Separate locations with commas', 'homeproz'),
'add_or_remove_items' => __('Add or remove locations', 'homeproz'),
'choose_from_most_used' => __('Choose from the most used locations', 'homeproz'),
'not_found' => __('No locations found.', 'homeproz'),
'menu_name' => __('Locations', 'homeproz'),
);
register_taxonomy('property_location', array('property'), array(
'hierarchical' => true,
'labels' => $location_labels,
'show_ui' => true,
'show_in_rest' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'location'),
));
}
add_action('init', 'homeproz_register_property_taxonomies');
/**
* Add default taxonomy terms on theme activation
*/
function homeproz_add_default_terms() {
// Default Property Types
$property_types = array('Residential', 'Commercial', 'Land', 'Multi-Family');
foreach ($property_types as $type) {
if (!term_exists($type, 'property_type')) {
wp_insert_term($type, 'property_type');
}
}
// Default Property Statuses
$property_statuses = array('Active', 'Pending', 'Sold');
foreach ($property_statuses as $status) {
if (!term_exists($status, 'property_status')) {
wp_insert_term($status, 'property_status');
}
}
// Default Locations (Minnesota cities near Albert Lea)
$locations = array('Albert Lea', 'Austin', 'Owatonna', 'Faribault', 'Mankato', 'Rochester');
foreach ($locations as $location) {
if (!term_exists($location, 'property_location')) {
wp_insert_term($location, 'property_location');
}
}
}
add_action('after_switch_theme', 'homeproz_add_default_terms');
/**
* Flush rewrite rules on theme activation
*/