Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Forum: Plugins
    In reply to: [User Groups] SQL Database

    wp_get_object_terms(2, 'user-group');

    Thread Starter jesperb

    (@jesperb)

    So, I’ve gotten a bit further, stuck again, this returns no results. What am I doing wrong?

    function filter_where_custom() {
    
            $latsearch = $_COOKIE["lat"]; //user latitude
            $lngsearch = $_COOKIE["long"]; //user longitude
    
            if((isset($_COOKIE["omrade"])) && ($_COOKIE["omrade"] == 'norrtalje')){
                $distance = 10; //set radius of 10km
            }else if(isset($_COOKIE["omrade"])){
                $distance = $_COOKIE["omrade"]; //set radius of user defined
            }else{
                $distance = 2; //set radius of 2km
            }
    
            global $wpdb;
    
            $latitude = $wpdb->get_col("SELECT * FROM $wpdb->postmeta WHERE meta_key = 'latitude'", 3);
            $longitude = $wpdb->get_col("SELECT * FROM $wpdb->postmeta WHERE meta_key = 'longitude'", 3);
            $lat = $latitude[0];
            $lng = $longitude[0];
    
            $where .= " AND '" . (6371 * acos( cos( deg2rad($latsearch) ) * cos( deg2rad( $lat ) ) * cos( deg2rad( $lng ) - deg2rad($lngsearch) ) + sin( deg2rad($latsearch) ) * sin( deg2rad( $lat ) ) ) ) < $distance . "'";
    
            return $where;
    }

    I’m applying the query like so:

    $today = date('ymd');
        $args = array(
            'post_type' => 'att-ata',
            'tax_query' => array(
    			'taxonomy' => 'typer',
    			'field' => 'slug',
    			'terms' => 'lunch'
    		),
            'posts_per_page' => -1,
    	    'meta_key' => 'lunch_datum',
            'meta_query' => array(
                array(
                    'key' => 'lunch_datum',
                    'value' => date('ymd'),
                    'compare' => '=',
                    'type' => 'DATE'
                )
            ),
    	    'orderby' => 'meta_value',
    	    'order' => 'ASC',
        );
        add_filter('posts_where', 'filter_where_custom');
        $lunchquery = new WP_Query($args);
        remove_filter('posts_where', 'filter_where_custom');

    Thread Starter jesperb

    (@jesperb)

    Realized I’m making it more complicated than it is. I’ve now separated the longitude and latitude into two separate meta fields. Still trying to figure out how to select them though.

Viewing 3 replies - 1 through 3 (of 3 total)