Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 19th, 2012  |  syntax: MySQL  |  size: 1.38 KB  |  views: 114  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. SELECT $wpdb->posts.ID, $wpdb->posts.post_title, $wpdb->terms.name, getthumbinfo.meta_value AS metainfo,
  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 getthumbid ON ($wpdb->posts.ID = getthumbid.post_id)
  11.         LEFT JOIN $wpdb->postmeta AS getthumbinfo ON (getthumbid.meta_value = getthumbinfo.post_id)
  12. WHERE $wpdb->posts.ID NOT IN ($post->ID)
  13.         AND thelat.meta_key = 'wpcf-latitude'
  14.         AND thelong.meta_key = 'wpcf-longitude'
  15.         AND $wpdb->posts.post_status = 'publish'
  16.         AND $wpdb->posts.post_type = 'places'
  17.         AND $wpdb->term_taxonomy.taxonomy = 'countries'
  18.         AND getthumbid.meta_key = '_thumbnail_id'
  19.         AND getthumbinfo.meta_key = '_wp_attachment_metadata'
  20. ORDER BY distance
  21. LIMIT 12