2

我有一个带有重力形式的列表字段,可以在自定义帖子类型中填充一些自定义字段。该网站是一个食谱提交网站,我正在寻找能够单独添加成分以获得更好的 SEO 的用户。我的问题是,当我提交表单时,只有成分下的最后一个输入字段被传递给配方。

我知道我需要一个序列化列表,因为这个自定义字段会拉出一个数组,但我完全不知道如何做到这一点。数组应该是这样的

 a:8:{i:0;s:26:"4oz piece of salmon/person";i:1;s:12:"1 egg/person";i:2;s:37:"1-2 multi-colored bell peppers/person";i:3;s:12:"Greek olives";i:4;s:9:"Olive oil";i:5;s:13:"Salt & Pepper";i:6;s:22:"Basil (fresh or dried)";i:7;s:0:"";}

我什至不知道从哪里开始为一个表单字段组合一个序列化数组,因此非常感谢任何朝着正确方向的轻推。

4

4 回答 4

0

Unfortunately Gravity Forms is configured to store these as separate meta records. One option is to customize the Gravity Forms forms_model.php file, create_post function, which unserializes the field contents and loops through each item to create a new post_meta record.

The following code should replace the case for field type list, and will prevent the creation of individual meta records on a predefined array of Gravity Form fields:

case "list" :
    $skipped_list_fields = array('<meta name for field to skip unserializing>',
        '<meta name for another field to skip unserializing>');
    $value = maybe_unserialize($value);
    if (in_array($meta_name, $skipped_list_fields)) {
        if(!rgblank($value))
            add_post_meta($post_id, $meta_name, $value);
    } else {
        if(is_array($value)){
            foreach($value as $item){
                if(is_array($item))
                    $item = implode("|", $item);

                if(!rgblank($item))
                    add_post_meta($post_id, $meta_name, $item);
            }
        }
    }
    break;
于 2014-01-17T14:59:48.823 回答
0

杰森,有人有类似的情况https://stackoverflow.com/questions/20591802/how-to-save-comma-separated-inputs-in-gravity-forms-to-a-global-array-on-form-su - 我认为您主题中functions.php中的类似编辑是方向......

于 2013-12-18T00:55:09.877 回答
0

将自定义字段表单字段配置为列表类型并像这样填写表单,我将所有成分视为单独的帖子元项目(但都附加到同一个键),就像这样

这与您所看到的不同,还是您试图实现不同的目标?

于 2013-12-18T02:25:09.280 回答
0

创建/编辑表单时,使用“高级字段”区域中的“列表”字段类型。该数据已经序列化并保存为单个字段中的数组。只需使用 gform_after_submission 挂钩将 GF 字段保存为 postmeta。

于 2016-03-31T23:56:31.453 回答