Gravity Forms field entries into wp_query loop

I have a simple function that filters the page content when form (ID 18) is submitted. It simply displays the entry of field (ID 13)…

add_action("gform_after_submission_18", "set_post_content", 10, 2);
function set_post_content($entry, $form){

    //getting post
    $post = get_post($entry["post_id"]);

    //changing post content
    $post->post_content = $entry[13];

}

Instead of simply displaying the entry, I need to use it as a variable within a wp_query loop..

Read More

The result I need is a loop of titles from all posts of the post type selected by form field (ID 13). The form field (ID 13) will be radio buttons with options for various custom post types..

<?php $loop = new WP_Query( array( 
    'post_type' => '$martinsposttype',
    'orderby' => 'title',
    'posts_per_page' => '-1', 
    'order' => 'ASC'
) ); ?>

<ul>            
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

<li><?php the_title(); ?></li>

<?php  endwhile; ?>
</ul>

How on earth do I tie this all up into my function so that the wp_query loop is performed upon submission and the $entry[13] is used for ‘post_type’ within that loop?

Related posts

Leave a Reply

1 comment

  1. On gform_after_submission save the gform entry in post meta.

    update_post_meta( $entry["post_id"], '_gform_submission_18_entry_13', $entry[13] );
    

    In your template:

    new WP_Query( array( 'post_type' => get_post_meta( get_the_ID(), '_gform_submission_18_entry_13', true ) ) );