Skip to content

Instantly share code, notes, and snippets.

@yankiara
Last active November 10, 2022 03:51
Show Gist options
  • Save yankiara/cc4745383ec54539ca73a6e9e997625d to your computer and use it in GitHub Desktop.
Save yankiara/cc4745383ec54539ca73a6e9e997625d to your computer and use it in GitHub Desktop.
Dynamically populate Fluentform dropdown select menu
<?php
add_filter('fluentform_rendering_field_data_select', function ($data, $form) {
if ($form->id != 10)
return $data;
if (\FluentForm\Framework\Helpers\ArrayHelper::get($data, 'attributes.name') != 'poste')
return $data;
$jobs = get_posts( [ 'post_type' => 'job' ] );
foreach( $jobs as $job ) {
$data['settings']['advanced_options'][] =
[
"label" => $job->post_title,
"value" => $job->post_title,
"calc_value" => ""
];
};
return $data;
}, 10, 2);
?>
@sandwebdesign
Copy link

The name 'fluenform_rendering_field_data_select' has changed in newer versions of Fluent Forms to 'fluentform_rendering_field_data_select' (with a t after fluen).

@yankiara
Copy link
Author

@sandwebdesign Thank you so much :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment