从自定义文本区域字段动态填充选择字段的选择

时间:2019-01-26 15:53:24

标签: wordpress advanced-custom-fields custom-fields contact-form-7

我有一个带有字段键的自定义文本区域字段:“规范”

https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/

我需要帮助来实现这一目标。我唯一需要的是添加一个动态选择字段,以从自定义文本区域字段中联系表单7。

但是当我使用https://wordpress.org/plugins/contact-form-7-dynamic-select-extension/

将过滤器添加到联系表单7时

选择字段值显示为一个see image

我需要在下拉列表中将文本字段的每个段落拆分为单独的值

当我添加此代码时,没有任何价值。

$get_custom_posts = explode("\n", $get_custom_posts);


    // remove any unwanted white space
    $get_custom_posts= array_map('trim', $get_custom_posts);

function cf7_dynamic_select_do_example1($choices, $args=array()) {


    $get_custom_posts = get_post_meta( get_the_ID(), 'specifications', false ); 
    // If we have posts, proceed
    if ($get_custom_posts) {

        // Foreach found custom post, we build the option using the [key] => [value] fashion
        foreach ($get_custom_posts as $custom_post) {
                $choices[$custom_post] = $custom_post;
            }

    // If we don't have posts, halt! Lets use a generic not found option
    } else { 

        // Just a generic option to inform nothing was found
        $choices['No posts found'] = 'No posts found';

    }
    return $choices;
}

add_filter('wpcf7_dynamic_select_example1', 
             'cf7_dynamic_select_do_example1', 10, 2);

0 个答案:

没有答案