Hello there fellow gravity users. This is proving a little difficult for me I have tried all manner of variations using wp_query and simply cannot get it to work. I therefore if possible would like some suggestions thanks.
The code below works correctly and populates a dropdown showing all posts from a certain category.
My issue arises when I try/wish to get a little more complex. I have a class_date stored in custom field class_date
I wish to query and display only posts that are
- category 9 (Class-Date)
- class_date - is today
- class_date - is in the future
Essentially I do not wish to have the ability to see past dates. This stops a user selecting past classes.
Your knowledge and wisdom would be gratefully appreciated.
Regards
Adey
Code below
// POPULATE DROPDOWN WITH POSTS
add_filter( 'gform_pre_render_18', 'populate_posts' );
add_filter( 'gform_pre_validation_18', 'populate_posts' );
add_filter( 'gform_pre_submission_filter_18', 'populate_posts' );
add_filter( 'gform_admin_pre_render_18', 'populate_posts' );
function populate_posts( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->type != 'select' || strpos( $field->cssClass, 'populate-posts' ) === false ) {
continue;
}
// Get posts that contains
// category id 1
// post status published
// order by title.
$posts = get_posts( 'numberposts=-1&category=9&post_status=publish&order_by=title' );
$choices = array();
foreach ( $posts as $post ) {
$choices[] = array( 'text' => $post->the_title, 'value' => $post->the_title );
}