I've got a CPT for random homepage banner images (so we can test different images and call to action language). I've got a custom field for the post type that accepts a specific ID for each banner so we can track it. I need to then get that ID into Gravity Forms.
Here's where the issue I'm having is coming in (and it's not Gravity Forms specific). I'm running a query in my function but it's giving me random ID's in Gforms instead of the actual ID of the banner at the time the form is filled out (which happens to be in a modal window). I'm using ACF to create the custom fields if that makes a difference (there is ACF specific code in my function).
Here's my function:
add_filter('gform_field_value_Banner_ID', 'populate_Banner_ID');
function populate_Banner_ID($value){
global $wp_query;
$args = array (
'post_type' => 'home_banners'
);
$home_banners = new WP_Query( $args );
while ( $home_banners->have_posts() ) : $home_banners->the_post();
$banner_id = get_field('home_banner_mail_id', $post->ID);
endwhile;
return $banner_id;
}
I've tried global $post;
too and that didn't work. Like I said, it's grabbing the custom field and populating Gravity Forms with it, but it seems to be grabbing a random version of the ID.
I've used the following on a page that doesn't load the form in a modal and it works as expected (and the ID on this page is dynamic too). I also tried this for the specific form I'm using in the modal, but it doesn't pick up the ID at all.
function populate_ppc_mail_id($value){
global $post;
$mail_id = get_field('ppc_mail_id', $post->ID);
return $mail_id;
}
add_filter('gform_field_value_mail_id', 'populate_ppc_mail_id');
Can someone point to what I'm doing wrong in my query that it's not picking up the correct ID? I've got the id loading as a css ID to test that it works, and that part is working as expected--it's just this specific query it seems to not want to cooperate.
Thanks in advance!