【问题标题】:ACF repeater fields (on and options page) within a Wordpress MU not returning dataWordpress MU 中的 ACF 转发器字段(在和选项页面上)不返回数据
【发布时间】:2016-05-10 22:38:11
【问题描述】:

我似乎在 Wordpress 多站点环境中检索 ACF 转发器字段(在选项页面上)时遇到问题。

(选项页面位于子站点上)

下面是我的代码:

$bids = Array();
$blogs = wp_get_sites();

foreach ($blogs as $blog) {
    array_push($bids, $blog['blog_id']);
}

$original_blog_id = get_current_blog_id();

$k = 0;
foreach($bids as $bid) {
    switch_to_blog($bid);

    // this works
    $centre_facebook_link = get_field('centre_facebook_link','option')  

    // this doesnt
    if( have_rows('about_team','option') ) {
        while ( have_rows('about_team','option') ) { the_row();
            $person_image = get_sub_field('person_image');
            $person_full_name = get_sub_field('person_full_name');
            break;
        }
    }
    switch_to_blog( $original_blog_id );
}

正如评论中所述,普通字段可以正常工作,但是当我尝试从转发器字段中检索数据时,它只是空了。

【问题讨论】:

    标签: php wordpress advanced-custom-fields multisite


    【解决方案1】:

    我认为您需要用于多站点环境的 ACF 同步插件。

    https://wordpress.org/plugins/acf-multisite-sync/

    如果它没有帮助检查: https://github.com/tmconnect/acf-relationship-multisite

    另一种方法是:

    switch_to_blog( $current_site );
    $GLOBALS['_wp_switched_stack'] = array();
    $GLOBALS['switched']           = FALSE;
    

    【讨论】:

    • 多站点同步用于在网络上轻松复制字段。我使用 php 导出代码执行此操作。我的字段出现在它应该出现的任何地方,并拉到前面,除了转发器字段。
    • 关系多站点允许我从网络中的其他站点提取帖子、帖子类型、页面。不相关,但我已经使用 switch_to_blog() 函数以编程方式执行此操作。
    • 在每个 switch_to_blog() 实例之后,您需要调用 restore_current_blog() 否则 WP 会认为它处于“切换”模式并可能返回不正确的数据。
    • foreach( $blog_ids as $blog_id ){ switch_to_blog( $blog_id ); //做东西 restore_current_blog(); }
    • 您可以编辑您的问题并粘贴您使用 restore_current_blog() 函数编写的代码吗?
    猜你喜欢
    • 2020-04-25
    • 2015-12-09
    • 2020-04-04
    • 2020-11-25
    • 2020-05-20
    • 1970-01-01
    • 2019-11-17
    • 2017-08-04
    • 1970-01-01
    相关资源
    最近更新 更多