Skip to content

Instantly share code, notes, and snippets.

@zartgesotten
Created August 11, 2025 13:35
Show Gist options
  • Save zartgesotten/d61a1c6a08b490ce283ba03fe19fd36a to your computer and use it in GitHub Desktop.
Save zartgesotten/d61a1c6a08b490ce283ba03fe19fd36a to your computer and use it in GitHub Desktop.
<?php
// CHANGE THE NUMBER AT THE END TO THE FORM ID
add_filter( 'gform_pre_render_2', 'populate_posts' );
add_filter( 'gform_pre_validation_2', 'populate_posts' );
add_filter( 'gform_pre_submission_filter_2', 'populate_posts' );
add_filter( 'gform_admin_pre_render_2', 'populate_posts' );
function populate_posts( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->type != 'select' || strpos( $field->cssClass, 'jobselect' ) === false ) {
continue;
}
$posts = get_posts( 'post_type=jobs&numberposts=-1&post_status=publish' );
$choices = array();
foreach ( $posts as $post ) {
$choices[] = array( 'text' => $post->post_title, 'value' => $post->post_title );
}
$field->placeholder = 'Bitte Traumjob aussuchen';
$field->choices = $choices;
}
return $form;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment