Support

Account

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

Helping

[WPGeoDirectory + ACF] Field calls fail on plugin pages. Ideas?

  • Hello everyone!

    I’m building a directory site with WPGeodirectory, and I’m having a heck of a time getting it to play nice with ACF. I’ve a ton of sites with ACF and have a pretty deep understanding of it, and I’ve exhausted my ideas on how to fix this.

    The core of the issue is that Advanced Custom Fields calls get obliterated if called on a page controlled bt the WPGeodirectory plugin. I know this might sound like it’s a WPGD issue, and it probably is, but I’m hoping someone has seen this effect with other plugins or has experience with WPGD + ACF.

    I’m trying to insert some custom fields the WPGD home page template, which works similarly to other plugin template customization (eg. WooCommerce – copy the template directory into theme directory, customize). Should be easy!

    However, when I use get_field, the_field, or get_field_object (even explicitly stating a numeric ID), I get junk data if it’s called from a page with WPGD actions.

    For my example I’m using get_field_object, since hopefully someone can use that information. The results are the same with the other functions too.

    // Getting an example field from the home page. 57 is the ID of the home page. Hard-coding it here so we can be sure there is nothing goofy about any $post->ID variables being passed in
    print_r (get_field_object( "home_intro_content", 57 ));

    On a standard page, this works great. It tells me all the information about the field from the home page. Here’s the output:

    Array ( [ID] => 331 [key] => field_58f12396b6471 [label] => Content [name] => home_intro_content [prefix] => acf [type] => textarea [value] => This text should introduce visitors to the website, explaining its purpose concisely.
    [menu_order] => 3 [instructions] => 200-ish words about the site. [required] => 1 [id] => [class] => [conditional_logic] => 0 [parent] => 323 [wrapper] => Array ( [width] => [class] => [id] => ) [_name] => home_intro_content [_prepare] => 0 [_valid] => 1 [default_value] => [placeholder] => [maxlength] => [rows] => [new_lines] => wpautop )

    Using this same exact code anywhere within a GD page, the function returns a bunch of nonsense.

    I’ve tried this in all sorts of ways, before and after actions and even trying with the field key instead of the name. It always gives me something like this, for the exact same code – note that the ID and field keys are wrong, which is very puzzling. It also always seems to think it is a repeater, when it should not be.

    Array ( [ID] => 251 [key] => field_5536634644729 [label] => Columns [name] => home_intro_content [prefix] => acf [type] => repeater [value] => [menu_order] => 0 [instructions] => [required] => 1 [id] => [class] => [conditional_logic] => 0 [parent] => 250 [wrapper] => Array ( [width] => [class] => [id] => ) [_name] => multiple_columns [_prepare] => 0 [_valid] => 1 [min] => 0 [max] => 4 [layout] => table [button_label] => Add Column [collapsed] => [parent_layout] => 5536632844728 [sub_fields] => Array ( [0] => Array ( [ID] => 252 [key] => field_553663864472a [label] => Content [name] => mc_content [prefix] => acf [type] => wysiwyg [value] => [menu_order] => 0 [instructions] => [required] => 1 [id] => [class] => [conditional_logic] => 0 [parent] => 251 [wrapper] => Array ( [width] => [class] => [id] => ) [_name] => mc_content [_prepare] => 0 [_valid] => 1 [tabs] => all [toolbar] => full [media_upload] => 1 [default_value] => [delay] => 0 ) ) )

    As you can see, all of the values are either blank or incorrect when using this function on a GD page. I’m wondering if, somehow, GD has a function that is blowing this up, and if there is a way I can circumvent it – maybe getting all of my fields at a priority higher than WPGD’s mangling actions? Ideas? I also tried adding fields to custom widgets and adding them to the WPGD widget areas. Same results!

    It’s worth mentioning that using get_post_meta on the same custom field seems to work properly!

    For additional reference, here’s a bit of the template I’m customizing. It seems so straightforward but it hates ACF 🙁
    WPGD home template source

  • 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;
    }
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘[WPGeoDirectory + ACF] Field calls fail on plugin pages. Ideas?’ is closed to new replies.