Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeoberdick/bc65abe70941856a83906fb20f16d562 to your computer and use it in GitHub Desktop.
Save mikeoberdick/bc65abe70941856a83906fb20f16d562 to your computer and use it in GitHub Desktop.
Create a drop down list that pulls a custom post type such as events in Ninja Forms
add_filter( 'ninja_forms_render_default_value', 'nf_hidden_field_values', 10, 3 );
// Populate event names for dropdown
add_filter( 'ninja_forms_render_options', function($options,$field_settings){
if( $field_settings['key'] == 'event_names' ) {
$args = array(
'post_type' => 'event',
'posts_per_page' => -1,
'post_status' => 'publish'
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ){
global $post;
while ( $the_query->have_posts() ){
$the_query->the_post();
$options[] = array('label' => get_the_title( ), 'value' => get_the_title( ));
}
wp_reset_postdata();
}
}
return $options;
},10,2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment