Support

Account

Home Forums ACF PRO Polylang & Location Front Page Reply To: Polylang & Location Front Page

  • It is possible to hook page_on_front option during acf/location/rule_match/page_type

    
    <?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();