title: Using ajax to call a php function, inside that function calling another function that wont fire
body: <p>Im using ajax on the front end to submit wp_query filters($args)
  I have a function in my functions.php called filter_function() this is what the ajax is submiting to.</p>
  
  <p>Inside filter_function() I have another function  distance_haversine() getting called thats inside my functions.php file but that function will not work inside filter_function()</p>
  
  <p>Example:</p>
  
  <pre><code>function distance_haversine($lat1, $lon1, $lat2, $lon2) {
        global $earth_radius;
        global $delta_lat;
        global $delta_lon;
        $alpha    = $delta_lat/2;
        $beta     = $delta_lon/2;
        $a   = sin(deg2rad($alpha)) * sin(deg2rad($alpha)) + cos(deg2rad($lat1)) *           cos(deg2rad($lat2)) * sin(deg2rad($beta)) * sin(deg2rad($beta)) ;
        $c        = asin(min(1, sqrt($a)));
        $distance = 2*$earth_radius * $c;
        $distance = round($distance, 4);
  
        return $distance;
  
  }
  
  
  function filter_function(){
  
  if ( isset( $_POST['distance_miles']  ) ) { 
  
    $distance_miles  = $_POST['distance_miles'];
  
  } else {
  
     $distance_miles  = 50;
  
  }
  
  
  
  $args = array(
      'orderby' =&gt; 'date', 
      'order' =&gt; $_POST['date'], 
      'post_type' =&gt; 'product', 
      'posts_per_page' =&gt; -1,
      's' =&gt; $_POST['search'],
  );
  
  $query = new WP_Query( $args );
  
  if( $query-&gt;have_posts() ) :
      while( $query-&gt;have_posts() ): $query-&gt;the_post();
        $event_lat     = get_post_meta(get_the_ID(),'prod-lat',true);
        $event_long    = get_post_meta(get_the_ID(),'prod-lng',true);
        $full_location = get_post_meta(get_the_ID(),'prod-full-address',true); 
        $earth_radius = 3960.00; # in miles
        $lat_1 = $event_lat;
        $lon_1 = $event_long;
        $lat_2 = $user_lat;
        $lon_2 = $user_long;
        $delta_lat = $lat_2 - $lat_1;
        $delta_lon = $lon_2 - $lon_1;
  
      //$lat_1, $lon_1, $lat_2, $lon_2 all have values
  
      $hav_distance = distance_haversine($lat_1, $lon_1, $lat_2, $lon_2);//this is not working
  
      var_dump($hav_distance); //&lt;------**This is outputing "float(0)"**
  
      if ( $hav_distance &lt;= $distance_miles ) { 
  
  ?&gt;
  
  &lt;li&gt;
      &lt;a href=""&gt;              
          &lt;?php if ( has_post_thumbnail() ) { ?&gt;
              &lt;?php the_post_thumbnail('thumbnail'); ?&gt;        
          &lt;?php } else { ?&gt;
              &lt;img src="/place-holder.jpeg"&gt;
          &lt;?php  }; ?&gt;                
      &lt;/a&gt;
  &lt;/li&gt;
  
  &lt;?php }
  
    endwhile;
  
      wp_reset_postdata();
  
    else :
  
      echo 'No posts found';
  
    endif;
  
    die();
  }
  </code></pre>