dongpu7881 2019-04-22 22:12
浏览 148
已采纳

多站点 - 从多站点上的另一个站点将ACF值从当前站点传递到Gravity Forms表单

I'm trying to pass data from Advance Custom Fields into my Gravity Forms form. The problem I'm running into is that the form is being generated from another site on the multisite via:

<?php switch_to_blog(1);?>   
     <?php echo do_shortcode( '[gravityform id="3" title="false" 
     description="false"]' ); ?>
<?php restore_current_blog(); ?>

In my functions.php file (for both blog 1 and the current site), I have:

add_filter( 'gform_field_value_lead_source_detail', 'populate_lead_source_detail' );
function populate_lead_source_detail( $value ) {

   $leadsourcedetail = get_field('lead_source_detail', $post->ID);
   return $leadsourcedetail;
}

add_filter( 'gform_field_value_lifecycle_status', 'populate_lifecycle_status' );
function populate_lifecycle_status( $value ) {
   $lifecycle = get_field('lifecycle_status', $post->ID);
   return $lifecycle;
}

add_filter( 'gform_field_value_lead_source', 'populate_lead_source' );
function populate_lead_source( $value ) {
   $leadsource = get_field('lead_source', $post->ID);
   return $leadsource;
}

add_filter( 'gform_field_value_channel', 'populate_channel' );
function populate_channel( $value ) {
   $channel = get_field('channel', $post->ID);
   return $channel;
}

add_filter( 'gform_field_value_expected_op_type', 'populate_expected_op_type' );
function populate_expected_op_type( $value ) {
   $expected = get_field('expected_op_type', $post->ID);
   return $expected;
}

The ACF fields work perfectly on blog 1, where the Gravity Form is being generated from, but I can't get them to pass the data to the form on the current current blog.

To make sure the ACF fields work (in general), I tested <?php the_field(); ?> for each of them, and the data is definitely there... so I'm assuming it has something to do with the fact that I'm pulling the form from a different site on the multisite.

Anyone have any ideas on how to pass data from my current site to the blog 1 form? Thanks in advance!

  • 写回答

2条回答 默认 最新

  • dtttlua7165 2019-04-24 03:10
    关注

    Went about this a completely different way. Found this in the Gravity Forms docs: https://docs.gravityforms.com/using-dynamic-population/ -- under shortcodes:

    [gravityform id=1 field_values=’parameter_name1=value1&parameter_name2=value2′]

    Wish I would've found this before I spent a whole day on this. Lol... Here were my steps after that:

    1. I exported/imported the Gravity Form onto another site in the multisite that shared the same theme (so I wasn't working on two different functions.php files; this is why the blog id and Gravity Forms id are different below).

    2. I removed all of the functions I originally created in the functions.php file that I stated earlier. (populate_lead_source_detail, populate_lifecycle_status, etc.)

    3. I created variables from the ACF fields for that page.

      <?php $lead_source_detail = get_field('lead_source_detail'); $lifecycle_status = get_field('lifecycle_status'); $lead_source = get_field('lead_source'); $channel = get_field('channel'); $expected_op_type = get_field('expected_op_type'); ?>

    4. I called the variables in the shortcode. (See below for my final code.)

                      <?php switch_to_blog(11);?>   
      
                          <?php echo do_shortcode( '[gravityform id="1" title="false" description="false" field_values="lead_source_detail='.$lead_source_detail.'&lifecycle_status='.$lifecycle_status.'&lead_source='.$lead_source.'&channel='.$channel.'&expected_op_type='.$expected_op_type.'"]' ); ?>
      
                      <?php restore_current_blog(); ?>
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名