我有以下代码,它使用Post标题以重力形式预先填充隐藏的下拉字段。帖子是事件。因此,如果事件已完全注册,它将在页面上返回一条消息,表明事件已满。所有作品都很棒,除非帖子(偶数标题)包含特殊字符,如&符号或撇号。在这些情况下,它总是显示事件已满。我猜我正在使用错误的功能来显示标题。我试图做出调整,但没有什么对我有用。任何帮助将不胜感激!
/**Gravity Forms Auto Populate Events Choice Hidden Field**/
add_filter( 'gform_form_post_get_meta_1', 'populate_posts' );
add_filter( 'gform_form_post_get_meta_11', 'populate_posts' );
add_filter( 'gform_pre_render_3', 'populate_posts' );
add_filter( 'gform_pre_validation_3', 'populate_posts' );
add_filter( 'gform_pre_submission_filter_3', 'populate_posts' );
add_filter( 'gform_admin_pre_render_3', 'populate_posts' );
function populate_posts( $form ) {
foreach ( $form['fields'] as &$field ) {
if ( $field->type != 'product' || strpos( $field->cssClass, 'populate-posts' ) === false ) {
continue;
}
// you can add additional parameters here to alter the posts that are retrieved
// more info: [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
$posts = get_posts( 'numberposts=-1&post_type=tribe_events' );
$choices = array();
$stock_quantity = get_field('max_tickets');
foreach ( $posts as $post ) {
$choices[] = array( 'text' => $post->post_title, 'value' => $post->post_title, 'limit' => $stock_quantity );
}
// update 'Select a Post' to whatever you'd like the instructive option to be
$field->placeholder = 'Select a Post';
$field->choices = $choices;
}
return $form;
}