Support

Account

Home Forums General Issues [WPGeoDirectory + ACF] Field calls fail on plugin pages. Ideas? Reply To: [WPGeoDirectory + ACF] Field calls fail on plugin pages. Ideas?

  • Figured it out. WPGEODIR is really stupidly coded.

    Add this to functions to fix it

    function override_the_stupid_plugin_filters($query) {
        global $wp_query, $wpdb, $geodir_post_type, $table, $dist, $mylat, $mylon, $s, $snear, $s, $s_A, $s_SA;
    
        // fix woocommerce shop products filtered by language for GD + WPML + Woocommerce
        if (!geodir_is_geodir_page()) {
            return;
        }
        
        //----------------------_START_CUSTOMIZED CODE---------------------------
        $removeFilterNicely = function($filter) {
            if( empty($GLOBALS['wp_filter'][$filter]) || empty($GLOBALS['wp_filter'][$filter]['callbacks']) ) {
                return;
            }
            foreach($GLOBALS['wp_filter'][$filter]['callbacks'] as $priority => $callbacks) {
                foreach($callbacks as $reference => $callback) {
                    if( stripos($callback['function'],'ACF') !== FALSE || stripos(get_class($callback['function']), 'ACF') !== FALSE ) {
                        unset($GLOBALS['wp_filter'][$filter]['callbacks'][$priority][$reference]);
                    }
                }
            }
        };
        $removeFilterNicely('query');
        $removeFilterNicely('posts_search');
        $removeFilterNicely('posts_fields');
        $removeFilterNicely('posts_join');
        $removeFilterNicely('posts_orderby');
        $removeFilterNicely('posts_where');
        /** remove all pre filters
        remove_all_filters('query');
        remove_all_filters('posts_search');
        remove_all_filters('posts_fields');
        remove_all_filters('posts_join');
        remove_all_filters('posts_orderby');
        remove_all_filters('posts_where');
        **/
        
        //----------------------_END_CUSTOMIZED CODE---------------------------
        
        if ((is_search() && isset($_REQUEST['geodir_search']) && $_REQUEST['geodir_search'] != '')):
            if (isset($_REQUEST['scat']) && $_REQUEST['scat'] == 'all')
                $_REQUEST['scat'] = '';
            //if(isset($_REQUEST['s']) && $_REQUEST['s'] == '+') $_REQUEST['s'] = '';
            if (isset($_REQUEST['sdist'])) {
                ($_REQUEST['sdist'] != '0' && $_REQUEST['sdist'] != '') ? $dist = esc_attr($_REQUEST['sdist']) : $dist = 25000;
            } elseif (get_option('geodir_search_dist') != '') {
                $dist = get_option('geodir_search_dist');
            } else {
                $dist = 25000;
            } //  Distance
    
            if (isset($_REQUEST['sgeo_lat'])) {
                $mylat = (float) esc_attr($_REQUEST['sgeo_lat']);
            } else {
                $mylat = (float) geodir_get_current_city_lat();
            } //  Latitude
    
            if (isset($_REQUEST['sgeo_lon'])) {
                $mylon = (float) esc_attr($_REQUEST['sgeo_lon']);
            } else {
                $mylon = (float) geodir_get_current_city_lng();
            } //  Distance
    
            if (isset($_REQUEST['snear'])) {
                $snear = trim(esc_attr($_REQUEST['snear']));
            }
    
            if (isset($_REQUEST['s'])) {
                $s = trim(esc_attr(wp_strip_all_tags($_REQUEST['s'])));
            }
    
            if ($snear == 'NEAR ME') {
                $ip = $_SERVER['REMOTE_ADDR'];
                $addr_details = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . $ip));
                $mylat = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_latitude]));
                $mylon = stripslashes(geodir_utf8_ucfirst($addr_details[geoplugin_longitude]));
            }
            if (strstr($s, ',')) {
                $s_AA = str_replace(" ", "", $s);
                $s_A = explode(",", $s_AA);
                $s_A = implode('","', $s_A);
                $s_A = '"' . $s_A . '"';
            } else {
                $s_A = '"' . $s . '"';
            }
            if (strstr($s, ' ')) {
                $s_SA = explode(" ", $s);
            } else {
                $s_SA = '';
            }
        endif;
    }