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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用