Wordpress Polylang+;首页上的ACF-字段组未显示在翻译页上

Wordpress Polylang+;首页上的ACF-字段组未显示在翻译页上,wordpress,Wordpress,我刚刚安装了Polylang(免费版),我有一个字段组,设置为显示在首页上 在管理中,字段在主语言的首页上正确显示,但在翻译后的首页上没有显示 我搜索了一下,看看会出什么问题,这显然是因为ACF只检查我们是否使用get\u选项(“page\u on\u front”)在头版 而且polylang似乎没有过滤值来设置右首页 所以我找到了这个mu插件: <?php class ACF_Page_Type_Polylang { // Whether we hooked page_on_f

我刚刚安装了Polylang(免费版),我有一个字段组,设置为显示在首页上

在管理中,字段在主语言的首页上正确显示,但在翻译后的首页上没有显示

我搜索了一下,看看会出什么问题,这显然是因为ACF只检查我们是否使用
get\u选项(“page\u on\u front”)
在头版

而且polylang似乎没有过滤值来设置右首页

所以我找到了这个mu插件

<?php

class ACF_Page_Type_Polylang {

  // Whether we hooked page_on_front
  private $filtered = false;

  public function __construct() {

      add_filter( 'acf/location/rule_match/page_type', array( $this, 'hook_page_on_front' ) );
  }

  public function hook_page_on_front( $match ) {

      if ( ! $this->filtered ) {
          add_filter( 'option_page_on_front', array( $this, 'translate_page_on_front' ) );
          // Prevent second hooking
          $this->filtered = true;
      }

      return $match;
  }

  public function translate_page_on_front( $value ) {

      if ( function_exists( 'pll_get_post' ) ) {
          $value = pll_get_post( $value );
      }

      return $value;
  }
}

new ACF_Page_Type_Polylang();
并将其转换为:

add_filter( 'option_page_on_front',function() { return '346' });
(346是翻译后的首页ID)

它会正确过滤前面的选项页,并且我的字段显示正确


你能帮我让mu插件工作吗?

我已经找到了一种方法让它工作,但我不知道这是不是正确的方法。。。你能告诉我吗

<?php

class ACF_Page_Type_Polylang {

  // Whether we hooked page_on_front
  private $filtered = false;

  public function __construct() {

      add_filter( 'acf/location/rule_match/page_type', array( $this, 'hook_page_on_front' ) );
  }

  public function hook_page_on_front( $match ) {

      // Abort if polylang not activated
      if ( !function_exists( 'pll_get_post' ) ) {
         return $match;
      }

      // Get the main language front page 
      $front_page = (int) get_option('page_on_front');

      // Get the translated page of the curent language
      $translated_page = pll_get_post($front_page);

      // Check if it's the same as the current page and set match to true if so
      if($translated_page === get_the_id()) {
        $match = true;
      }

      return $match;
  }
}

new ACF_Page_Type_Polylang();

<?php

class ACF_Page_Type_Polylang {

  // Whether we hooked page_on_front
  private $filtered = false;

  public function __construct() {

      add_filter( 'acf/location/rule_match/page_type', array( $this, 'hook_page_on_front' ) );
  }

  public function hook_page_on_front( $match ) {

      // Abort if polylang not activated
      if ( !function_exists( 'pll_get_post' ) ) {
         return $match;
      }

      // Get the main language front page 
      $front_page = (int) get_option('page_on_front');

      // Get the translated page of the curent language
      $translated_page = pll_get_post($front_page);

      // Check if it's the same as the current page and set match to true if so
      if($translated_page === get_the_id()) {
        $match = true;
      }

      return $match;
  }
}

new ACF_Page_Type_Polylang();