Created
June 6, 2016 00:41
-
-
Save iansvo/8138934d7de15e07270bf915be833e92 to your computer and use it in GitHub Desktop.
Populate Ninja Forms List with Custom Post Types
This file contains 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 | |
function locations_prepopulate_forms($data, $field_id) { | |
global $post; | |
// Populates a specific list (by field ID) with the "locations" cpt's | |
if($field_id == 27) { | |
$args = array( | |
'post_type' => 'location', | |
); | |
$query = new WP_Query( $args ); | |
if ( $query->have_posts() ) { | |
$data['list']['options']=array(); | |
while ( $query->have_posts() ) { | |
$query->the_post(); | |
$data['list']['options'][] = array( | |
'label' => get_the_title(), | |
'value' => $post->post_name, | |
'calc' => null, | |
'selected' => 0 | |
); | |
} | |
} | |
wp_reset_postdata(); | |
} | |
return $data; | |
} | |
add_filter('ninja_forms_field','locations_prepopulate_forms', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment