Advertisement
sshuvro58

Untitled

May 29th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /* Retrive the city of suite */
  2.  
  3. function retive_city_of_suite($suite_id, $return_array_type=false) {
  4. $temp_property_id = get_post_meta($suite_id, 'id_property_under', TRUE);
  5.  
  6.  
  7. global $wpdb;
  8.  
  9. $temp_city = $wpdb->get_var("SELECT "
  10. . " {$wpdb->prefix}terms.term_id FROM {$wpdb->prefix}term_relationships "
  11. . " INNER JOIN {$wpdb->prefix}posts ON {$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id"
  12. . " INNER JOIN {$wpdb->prefix}term_taxonomy ON {$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}term_taxonomy.term_taxonomy_id"
  13. . " INNER JOIN {$wpdb->prefix}terms ON {$wpdb->prefix}term_taxonomy.term_id = {$wpdb->prefix}terms.term_id WHERE {$wpdb->prefix}posts.ID = $temp_property_id"
  14. . " AND {$wpdb->prefix}posts.post_status = 'publish'");
  15.  
  16. $parent = get_term_by('id', $temp_city, 'city');
  17. while ($parent->parent != 0) {
  18. $parent = get_term_by('id', $parent->parent, 'city');
  19. }
  20.  
  21. if($return_array_type){
  22. return array('name'=>$parent->name,'term_id' =>$parent->term_id, 'slug'=>$parent->slug);
  23. }else{
  24. return $parent->name;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement