0

I am developing a website for real estates. I was wondering that how can I add a dropdown to my custom forms (theme my login plugin) for cities states etc. The basic point is that I dont want to add new tables in the database. I want to achieve this without that.

Thanks

2
  • Many real estate themes use custom taxonomy to list locations in their theme, you can use that too
    – Mamaduka
    Commented Aug 15, 2011 at 8:28
  • @Mamaduka: Thanks. Can I get some in-depth example, I am newbie in the world of wordpress :( Commented Aug 15, 2011 at 10:24

1 Answer 1

1

You can register custom taxonomy like so:

<?php
// Register custom taxonomy for locations
function mamaduka_register_taxonomy_location() {
    register_taxonomy( 'location', array( 'post' ), array(
        'hierarchical' => true,
        'label' => 'Locations',
        'public' => true,
    ));
}
add_action( 'init', 'mamaduka_register_taxonomy_location' );
?>

for more information about custom taxonomy see Codex: http://codex.wordpress.org/Function_Reference/register_taxonomy

3
  • That was a kind reply and thanks for that. One more thing, I will be doing it like: 1) add cities first and then 2) add locations of each city. So it will be like hierarchy. How can I get only the parent values (i.e. cities) in one place of custom theme and then child values (i.e. locations) in the other? Commented Aug 16, 2011 at 3:09
  • and I did it on my own. Thanks Mamaduka for the guidance. Mamaduka please correct me if I am wrong with my approach. A little more googling lead me to these functions: get_terms (to get the parents of my custom taxonomy i.e cities), get_term_children (to get the children id of each term in an array) and finally get_term_by (to get the childrens of each parent of my taxonomy i.e locations). Commented Aug 16, 2011 at 3:44
  • You're welcome. I had similar question so you can see here how to get only parent terms - wordpress.stackexchange.com/questions/24582/…, your approach is right, see Coxed page for get_term_children there great basic example
    – Mamaduka
    Commented Aug 16, 2011 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.