Ask your WordPress questions! Pay money and get answers fast! (more info)

Geo My Wordpress Plugin Question WordPress

  • SOLVED

I am using the plugin Geo My WP to power a business directory on my site. I have created a ticket on the plugin doc site that has the question I need answered, but still waiting on the answer and trying to speed up that process.

Here is my exact question that I posted on the on the plugin doc site that has all the details: https://geomywp.com/support/topic/dynamic-starting-address-for-loaded-results-page/

Basically, just trying to figure out how to adjust that function in order to get the page to load with the custom field I am using set as the starting address. Current function I am using that is not working:


function gmw_formload( $gmw ) {

if ( $gmw['ID'] == 5) {
$gmw['address_filter'] = the_field('city_address');
}

return $gmw;
}
add_filter( 'gmw_pt_default_form_values' , 'gmw_formload', 99 );


No luck so far in getting this to work. Any help would be appreciated.

Answers (2)

2015-09-07

dimadin answers:

Depending on where is this form displayed, you need to retrieve post's ID from which you want to get value for a field 'city_address'.

Assuming that this is single post view, you don't need to know post's ID and can use global post object. This get be done in function the_field() you are using. Problem is that this function echoes content so you can't use it in a filter (no matter which). You need to use its parent function, get_field().

In that case, you would just change this function in your code:



function gmw_formload( $gmw ) {



if ( $gmw['ID'] == 5) {

$gmw['address_filter'] = get_field('city_address');

}



return $gmw;

}

add_filter( 'gmw_pt_default_form_values' , 'gmw_formload', 99 );


Let me tell you if this changed anything, though I am not sure if you are filtering right value.


jpequens comments:

Changing to get_field did not work. I am not sure if it is the right value as well, but it is the only value I can find in the support forums. Not sure how to check if it is correct or not.


dimadin comments:

What you are trying is to have the name of the city in field "Enter Address..."? Does search results below also need to be limited to that city by default?


jpequens comments:

get_field did work when I added the second piece. This is what got it working:

function gmw_formload( $gmw ) {

if ( $gmw['ID'] == 5) {
$gmw['page_load_results']['address_filter'] = get_field('city_address');
}

return $gmw;
}
add_filter( 'gmw_pt_default_form_values' , 'gmw_formload', 99 );


Thanks for all the help! An exciting feeling to get it working!

2015-09-07

Arnav Joy answers:

can you show me your site ? where there is form.


jpequens comments:

Here is the page I am trying to get to work. The form on top is not styled yet. It is set to load the results as the page opens.

Currently I do not have a starting city defined in the field that asks for it in the plugin when creating the form.

http://floattanks.net/new-york/new-york/