Advertisement
Guest User

Untitled

a guest
Oct 19th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.24 KB | None | 0 0
  1. SELECT $wpdb->posts.ID, $wpdb->posts.post_title, $wpdb->terms.name, thethumbnail.meta_value AS thumbnail_id,
  2.     thelat.meta_value AS latitude,thelong.meta_value AS longitude,
  3.     ASIN ( SQRT (POWER(SIN(($lat - thelat.meta_value)*pi()/180 / 2),2) + COS($lat * pi()/180) * COS(thelat.meta_value *pi()/180) * POWER(SIN(($long - thelong.meta_value) *pi()/180 / 2), 2) ) ) AS distance
  4. FROM $wpdb->posts
  5.     LEFT JOIN $wpdb->postmeta AS thelong ON ($wpdb->posts.ID = thelong.post_id)
  6.     LEFT JOIN $wpdb->postmeta AS thelat ON ($wpdb->posts.ID = thelat.post_id)
  7.     LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
  8.     LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
  9.     LEFT JOIN $wpdb->terms ON ($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)
  10.     LEFT JOIN $wpdb->postmeta AS thethumbnail ON ($wpdb->posts.ID = thethumbnail.post_id)
  11. WHERE $wpdb->posts.ID NOT IN ($post->ID)
  12.     AND thelat.meta_key = 'wpcf-latitude'
  13.     AND thelong.meta_key = 'wpcf-longitude'
  14.     AND $wpdb->posts.post_status = 'publish'
  15.     AND $wpdb->posts.post_type = 'places'
  16.     AND $wpdb->term_taxonomy.taxonomy = 'countries'
  17.     AND thethumbnail.meta_key = '_thumbnail_id'
  18. ORDER BY distance
  19. LIMIT 12
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement