I have child categories (cities) which belongs to parent categories (countries). I get a list of categories (cities-countries) as below:
$categor = $wpdb->get_results("select * from $wpdb->terms c,$wpdb->term_taxonomy tt where tt.term_id=c.term_id and tt.taxonomy='hotelcategory' and c.name != 'Uncategorized' and c.name != 'Blog' $substr order by c.name");
for($i=0;$i<count($categor);$i++)
{
echo '"'.$categor[$i]->name.' - '.$categor[$i]->parent.'",';
}
I use the retrieved data in jquery autocomplete, and i can get the parent category id but not the name.
The problem is for example there are many cities named “Paris”, so when i type in paris, i get like 8-9 cities with same name.(Picture1)
What i’d like to do is to have their parent category names beside the category.(Picture2)
http://s7.postimage.org/k85dhd4sr/catn.jpg
You just have the ID of the parent-term, so if you want the actual name of the term you have to fetch it. One way to do that is to simply join the term table again for the
parent
ID:An alternative solution without any SQL could look like that:
This solution is admittedly a bit more verbose, but you don’t have to worry with SQL or the database layout.