简体   繁体   English

将ACF字段的值添加到当前“自定义帖子”类型页面中的“重力表单”中

[英]Add value of ACF field to Gravity Form in current Custom Post type page

I have a Custom Post Type called "Profile". 我有一个称为“个人资料”的自定义帖子类型。 With Advanced Custom Fields (ACF) I've added the additional field PDF_file , which is used to upload a file to the newly created post, and on the frontend is a button linked to the uploaded file. 使用高级自定义字段 (ACF),我添加了附加字段PDF_file ,该字段用于将文件上传到新创建的帖子,并且在前端是一个链接到上传文件的按钮。

Using Gravity Forms I want visitors to be able to send this file to a friend by sending the file link, which is basically the value of the " PDF_file " field. 使用重力表单,我希望访问者能够通过发送文件链接将该文件发送给朋友,该文件链接基本上是“ PDF_file ”字段的值。

I can't seem to find out how I can retreive the value and insert it in to the Gravity Form. 我似乎无法找出如何获取该值并将其插入“重力表”中的方法。

I have implemented the Gravity in the single custom post type template by using: 我已经使用以下方法在单个自定义帖子类型模板中实现了Gravity:

<?php gravity_form(15, $display_title=false, $display_description=true, $display_inactive=false, $field_values=null, $ajax=true, $tabindex); ?>

Your best bet it is to populate the URL of the field (which I assume is stored in the ACF custom field) into a hidden field on your Gravity Form. 最好的选择是将字段的URL(我假设存储在ACF自定义字段中)填充到重力窗体上的隐藏字段中。 The easiest way to accomplish this is with "dynamic population". 实现此目的的最简单方法是“动态填充”。

http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population

In your case, I would recommend going with the "hook" method. 在您的情况下,我建议您使用“ hook”方法。

add_filter( 'gform_field_value_your_parameter', 'my_custom_population_function' );
function my_custom_population_function( $value ) {
    global $post;
    return function_exists( 'get_field' ) ? get_field( 'PDF_file', $post->ID ) : false;
}

You can update your_parameter in the filter name to whatever you'd like to call the parameter. 您可以将过滤器名称中的your_parameter更新为您要调用该参数的名称。 Just make sure you populate that parameter name in the dynamic population "Parameter Name" input on the field settings for your hidden field. 只需确保在隐藏字段的字段设置的动态填充“参数名称”输入中填充该参数名称即可。

I have had some success with this: 我在此方面取得了一些成功:

add_filter( 'gform_field_value_job_ref', 'gf_filter_job_ref' );
function gf_filter_job_ref() {
    return esc_attr( get_field( 'job_ref' ) );
}

Ensure that your hidden field is set named 'job_ref' (in this case) and that the advanced > parameter field is also 'job_ref'. 确保您的隐藏字段设置为“ job_ref”(在这种情况下),并且高级>参数字段也为“ job_ref”。

Thanks go to this blog post: http://www.engagewp.com/create-invoices-gravity-forms-wordpress/ 感谢访问此博客文章: http : //www.engagewp.com/create-invoices-gravity-forms-wordpress/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM