Created
August 11, 2025 13:35
-
-
Save zartgesotten/d61a1c6a08b490ce283ba03fe19fd36a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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