我在联系人表单7中有一个动态下拉/选择框,我相信它是基于以下内容:https://gist.github.com/morgyface/56474f0a37abb7d622880daf6eff6e40
我已经有一段时间没有做这个了,所以细节有点模糊,但我们直到最近才意识到订单有问题,我甚至不知道从哪里开始解决它。我记得这整件事花了我太长时间才弄明白我现在的想法,而且我已经很久没有在里面挖掘了,所以我在这里过得很艰难!
以下是修改后的代码,除了订单外,它也在工作:
add_action( \'wpcf7_init\', \'postselect2\' );
function postselect2() {
    wpcf7_add_form_tag( \'postlist\', \'custom_post_select2\', true ); //If the form-tag has a name part, set this to true.
}
function custom_post_select2( $tag ) {
    $posttype = \'tribe_events\';
    $date = new DateTime();
    $today = $date->getTimestamp();
    $args = array(
        \'post_type\'         => $posttype,
        \'post_status\'       =>  \'publish\',
        \'numberposts\'       => -1,
        \'meta_key\'          => \'_EventStartDate\',
        \'orderby\'           => \'meta_value_num\',
        \'order\'             => \'ASC\',
        \'meta_query\'        => array(
            \'relation\'          => \'AND\',
                array(
                    \'key\'           => \'_EventStartDate\',
                    \'compare\'       => \'>=\',
                    \'value\'         => $today,
                )
        )
    );
    $posts = get_posts( $args );
    $output = "<select name=\'" . $tag[\'name\'] . "\' id=\'" . $tag[\'name\'] . "\' onchange=\'document.getElementById(\\"" . $tag[\'name\'] . "\\").value=this.value;\'><option></option>";
    // if you\'ve set the name part to true in wpcf7_add_form_tag use $tag[\'name\'] instead of $posttype as the name of the select.
    foreach ( $posts as $post ) {
            $postid = $post->ID;
            $posttitle = get_the_title( $postid );
            $postslug = get_post_field( \'post_name\', $postid );
            $postdate = tribe_get_start_date($post, false, $date_format=\'m/d/y\');
        $output .= \'<option value="\' . $postdate . \' \' . $posttitle . \'">\' . $postdate . \' \' . $posttitle . \'</option>\';
    } // close foreach
    $output .= "</select>";
    return $output;
}
 这里的另一个方面是,由于有一些事件是人们填写表格要求注册的,所以在“今天”之前发生的事件显然不应该出现在列表中(有效)。
下面是一个输出示例:
这些事件在“实际事件”页面上正确显示,其中有来自“现代部落”的[主要是股票]循环,因此我相信这不是事件帖子本身的问题。
TIA获取任何提示或建议:)
 
                    最合适的回答,由SO网友:iprobablyhavenoanswers 整理而成
                    对于任何一个遇到同样的利基问题的可怜的灵魂来说,答案都很简单,令人沮丧。我本应该使用tribe_get_events 我相信现代部落开发人员已经努力编写了这个函数。
无论如何,以下是最终的解决方案:1)在联系人表单7中添加自定义选择框,2)使用现代部落的活动日历中即将到来的活动填充该框:
// Create post dropdown function for Contact Form 7 (not required)
add_action( \'wpcf7_init\', \'postselect2\' );
    function postselect2() {
        wpcf7_add_form_tag( \'postlist\', \'custom_post_select2\', true );
    }
    function custom_post_select2( $tag ) {
    $events = tribe_get_events( array(
        \'posts_per_page\' => -1,
        \'start_date\' => date( \'Y-m-d H:i:s\' )
    ) );
    $output = "<select name=\'" . $tag[\'name\'] . "\' id=\'" . $tag[\'name\'] . "\' onchange=\'document.getElementById(\\"" . $tag[\'name\'] . "\\").value=this.value;\'> <option></option>";
    foreach ( $events as $event ) {
        $output .= \'<option value="\' . $event->EventStartDate . \' \' . $event->post_title . \'">\' . tribe_get_start_date( $event, true, \'n/j/Y @ g:ia\' ) . \' \' . $event->post_title . \'</option>\';
    } // close foreach
    $output .= "</select>";
    return $output;
} // close function