use dates of events as dropdown in contactform7

Home Forums Calendar Products Events Calendar PRO use dates of events as dropdown in contactform7

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #969242
    thomas
    Participant

    hi,

    i have a post with contactform7 form. this post has a title, which is accessible via [_post_title] in contactform7.
    i like to create a select field inside the form, where users can select all the start dates of the events which have the same title as the post where the contactform7 is shown.

    in short: output start date from event post with same title as blog post.
    hope i made myselft clear enough.
    best regards
    thomas

    #969442
    Brook
    Participant

    Howdy Thomas,

    I would love to help you with that. That makes a lot of sense. It will require some PHP know-how to build. You can query for a WordPress Post, like an event, by constructing an ordinary WP_Query for the post type “tribe_events”. If you want to query based on the Title, and not the slug, then checkout this StackOverflow post on how to augment WP_Query functionality to add “post_title_like”.

    Once you have the return query, just run tribe_get_start_date() on each post to obtain it’s start date. From there you can populate a CF7 form with the necessary values using their PHP API.

    Does that all make sense? Will that work for you? Please let us know.

    Cheers!

    – Brook

    #969656
    thomas
    Participant

    hey brook,

    so far i got:

    <?php query_posts(array(
    'post_type' => 'tribe_events',
    'order'     => 'ASC',
    'tag'       => basename( get_permalink() )
    ));
    while (have_posts()) : the_post(); $event = get_post();
    echo "<br>";
    echo tribe_get_start_date( $event, $displayTime = false, $dateFormat = "l, j. F Y" );
    if ( -1 == $event->menu_order ) { echo " - bereits ausgebucht"; };
    endwhile; wp_reset_query(); ?>

    which checks if the tag of an event post is the same like the slug of the blog post.
    i tried some stuff with the post title but i got no success at all…

    #969796
    Brook
    Participant

    Nice work. That’s probably a better idea anyways. Using the title is inherently inflexible, but a tag is a great idea. Does that tag work for you? Are you still having problem, or can I help further?

    – Brook

    #969806
    thomas
    Participant

    hey brook,

    yes of course! as you can read in the first post i’d like to have those dates included in a contactform7 form as a select dropdown menu. how can i send the dates from the query to the contactform.

    [select menu-dropdown "date1" "date2" "date3"]

    regards
    thomas

    #969886
    Brook
    Participant

    Howdy Thomas, for that you will have to ask CF7 or consult their documentation. I am not familiar enough with their app to say. I did use it one time, and if I recall correct they had a PHP API where you create CF7 forms. So instead of using a shortcode, you would use PHP. But I am not certain, simply put I am just not a CF7 expert.

    I wish I could be of more help. If you do have more questions to The Events Calendar though, please let me know.

    Cheers!

    – Brook

    #970866
    thomas
    Participant

    hey brook,

    i found out that you can activate shortcodes in contactform7 with this in your function.php
    add_filter( 'wpcf7_form_elements', 'do_shortcode' );

    all i need is to write a shortcode that does the following things:
    – get the dates (i allready achieved this part)
    – wrap them in the form of the select field (this is where i need help)

    #971005
    Brook
    Participant

    It sounds like you were not able to find good documentation on how to use their API without shortcodes. I am sorry to hear that. I am not quite sure what that line of code you mentioned will do for you. Hooking into wpcf7_form_elements makes sense, but I doubt you want to attach do_shortcode to it.

    One thing that just occurred to me is that you could use do shortcode to output the exact string you mentioned earlier:

    [select menu-dropdown "date1" "date2" "date3"]

    If all you need is to generate the same output as that string, then you could just concatenate a string together based on the event dates and output it with do_shortcode(). As an example using untested code and tribe_get_events():

    $ev_query = tribe_get_events(array(
    'eventDisplay' => 'custom',
    'tag' => basename( get_permalink() )
    ));
    
    $sc_args = '';
    
    foreach ($ev_query as $event) {
    $sc_args .= ' "' . tribe_get_start_date( $event, $displayTime = false, $dateFormat = "l, j. F Y" ) . '"';
    }
    
    echo do_shortcode('[select menu-dropdown' . $sc_args .']');

    But I am not sure how that will work with CF7’s setup. It is very possible that you will need to some incredible trickery to get that working. You might just need to write your own shortcode which runs the above code, or you might have to do something much more involved.

    I really do wish I could be of more help. Personally I hate being caught between two support realms. Unfortunately though, I am just not a CF7 expert. At this point you have all of the drop down arguments as you have extracted the data from The Events Calendar. Now you just need to know what options if any CF7 offers for importing dynamic data.

    Cheers!

    – Brook

    #984361
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘use dates of events as dropdown in contactform7’ is closed to new replies.