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条)

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动