Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_filter('query_vars','sw_add_vars');
  2. add_filter('posts_join', 'sw_join' );
  3. add_filter('posts_select', 'sw_join' );
  4.  
  5. $bio_keys = array('dob','loc');
  6.  
  7. function sw_add_vars($q) {
  8.     global $bio_keys;
  9.     var_dump($q);
  10.     foreach ($bio_keys as $key) {
  11.         $q[] = $key;
  12.     }
  13.     var_dump($q);
  14.     return $q;
  15. }
  16.  
  17. function sw_join($join) {
  18.     global $wpdb; global $wp_query; global $bio_keys;
  19.     foreach ($bio_keys as $key) {
  20.         if (isset($wp_query->query_vars[$key])) {
  21.             $join .=
  22.                 " JOIN ".$wpdb->postmeta." AS ".$key." ON (
  23.                     ".$wpdb->posts.".ID = ".$key.".post_id
  24.                     AND ".$key.".meta_value = '".$wp_query->query_vars[$key]."'
  25.                   ) "
  26.         }
  27.     }
  28.     echo $join;
  29.     return $join;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement