Pulling data for WordPress Jetpack plugin contact form

I have a small form on my website, which I created using Jetpack plugin (it has built-in contact form creator).

I want to pull options for select input from my custom-post-type “artist” (using the titles of the posts). Is there a way to do it?

Read More
[contact-field label='Artist' type='select' required='1' options='i want my titles go here separated by commas plus "other" option'/]

The code for the field looks like this. I believe I need to do some php+jquery stuff in this page template, but I can’t seem to get it.

Related posts

Leave a Reply

1 comment

  1. With some creativity, yes, it’s possible 🙂

    We create another Shortcode to create a “virtual” JetPack shortcode.

    I tested this using the default post post_type.

    add_shortcode( 'my-jet-form', 'so_14003883_jet_form' );
    
    function so_14003883_jet_form( $atts, $content ) 
    {
        // Query our post type, change accordingly
        $posts = get_posts( array(
            'post_type'    => 'post',
            'numberposts'  => -1,
            'post_status'  => 'publish'
        ) );
    
        // Build an array of post titles
        $titles = array();
        foreach( $posts as $post )
        {
            $titles[] = $post->post_title;
        }
    
        // Convert array into comma sepparated string
        $posts_select = implode( ',', $titles );
    
        // Make JetPack shortcode
        $return = do_shortcode( '[contact-form][contact-field label="Name" type="name" required="1"/][contact-field label="Artist" type="select" options="' . $posts_select . '"/][/contact-form]' );
        return $return;
    }
    

    Usage:

    • adjust the desired post type
    • adjust the do_shortcode part to suit your original shortcode
    • put the shortcode [my-jet-form] wherever you want
    • voilÃ