Trying to force blog posts to work as products or portfolios? Custom Post Types create dedicated content structures.
// functions.php - Create Property Custom Post Type
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,
'query_var' => true,
'rewrite' => array('slug' => 'property'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 5,
'menu_icon' => 'dashicons-building',
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields'),
'taxonomies' => array('property_type', 'property_location'),
'show_in_rest' => true // Enable Gutenberg editor
);
register_post_type('property', $args);
}
add_action('init', 'register_property_post_type');
// Add custom taxonomies
function register_property_taxonomies() {
// Property Type (Apartment, Villa, Office, etc.)
register_taxonomy('property_type', 'property', array(
'labels' => array(
'name' => 'Property Types',
'singular_name' => 'Property Type'
),
'hierarchical' => true,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'property-type'),
'show_in_rest' => true
));
// Property Location (City, District, etc.)
register_taxonomy('property_location', 'property', array(
'labels' => array(
'name' => 'Locations',
'singular_name' => 'Location'
),
'hierarchical' => true,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'location'),
'show_in_rest' => true
));
}
add_action('init', 'register_property_taxonomies');
