WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question
Many real estate themes use custom taxonomy to list locations in their theme, you can use that too – Mamaduka Aug 15 '11 at 8:28
@Mamaduka: Thanks. Can I get some in-depth example, I am newbie in the world of wordpress :( – booota Aug 15 '11 at 10:24
up vote 1 down vote accepted

You can register custom taxonomy like so:

// 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

share|improve this answer
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? – booota Aug 16 '11 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). – booota Aug 16 '11 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 Aug 16 '11 at 7:08
Once again thanks. – booota Aug 18 '11 at 9:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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