Taxonomies

Custom taxonomies could be found inside realia/includes/taxonomies folder. Before you start working with taxonomies, make sure that you are familiar with all nuances of register_taxonomy function.

List of all available custom taxonomies defined by plugin:

  • Locations
  • Property types
  • Statuses
  • Amenities
  • Materials

Changing taxonomy slug

Below you can see how we can change the custom taxonomy slug. Logic is quite straightforward. First of all we will remove all definition and then we will register it with new slug.

remove_action( 'init', array( 'Realia_Taxonomies_Amenities', 'definition' ) );

add_action( 'init', 'my_custom_taxonomy' );

function my_custom_taxonomy() {
    $custom_taxonomy_labels = array(
        'name'              => __( 'Custom Taxonomies', 'realia'),
        'singular_name'     => __( 'Custom Taxonomy, 'realia'),
        'search_items'      => __( 'Search Custom Taxonomy', 'realia'),
        'all_items'         => __( 'All Custom Taxonomies', 'realia'),
        'parent_item'       => __( 'Parent Custom Taxonomy', 'realia'),
        'parent_item_colon' => __( 'Parent Custom Taxonomy:', 'realia'),
        'edit_item'         => __( 'Edit Custom Taxonomy', 'realia'),
        'update_itm'        => __( 'Update Custom Taxonomy', 'realia'),
        'add_new_item'      => __( 'Add New Custom Taxonomy', 'realia'),
        'new_item_name'     => __( 'New Custom Taxonomy', 'realia'),
        'menu_name'         => __( 'Custom Taxonomies', 'realia'),
    );

    register_taxonomy( 'custom-taxonomies', 'property', array(
        'labels'            => $custom_taxonomy_labels,
        'hierarchical'      => true,
        'query_var'         => 'custom-taxonomy',
        'rewrite'           => array( 'slug' => 'NEW-CUSTOM-SLUG-HERE') ,
        'public'            => true,
        'show_ui'           => true,
        'show_admin_column' => true,
    ) );
}

Adding new taxonomy to property

add_action( 'init', 'my_custom_taxonomy' );

function my_custom_taxonomy() {
      $custom_taxonomy_labels = array(
        'name'              => __( 'Custom Taxonomies', 'realia'),
        'singular_name'     => __( 'Custom Taxonomy, 'realia'),
        'search_items'      => __( 'Search Custom Taxonomy', 'realia'),
        'all_items'         => __( 'All Custom Taxonomies', 'realia'),
        'parent_item'       => __( 'Parent Custom Taxonomy', 'realia'),
        'parent_item_colon' => __( 'Parent Custom Taxonomy:', 'realia'),
        'edit_item'         => __( 'Edit Custom Taxonomy', 'realia'),
        'update_itm'        => __( 'Update Custom Taxonomy', 'realia'),
        'add_new_item'      => __( 'Add New Custom Taxonomy', 'realia'),
        'new_item_name'     => __( 'New Custom Taxonomy', 'realia'),
        'menu_name'         => __( 'Custom Taxonomies', 'realia'),
    );

    register_taxonomy( 'custom-taxonomies', 'property', array(
        'labels'            => $custom_taxonomy_labels,
        'hierarchical'      => true,
        'query_var'         => 'custom-taxonomy',
        'rewrite'           => array( 'slug' => __( 'custom-taxonomy', 'realia' ) ),
        'public'            => true,
        'show_ui'           => true,
        'show_admin_column' => true,
    ) );
}

Removing taxonomy

All taxonomies definition are wrapped in init hooks so it is easy to remove custom taxonomy only by defining remove_action(). Below you can see example how to remove amenities taxonomy.

remove_action( 'init', array( 'Realia_Taxonomies_Amenties', 'definition' ) );