Beee4life / acf-city-selector

An ACF extension to create a new field type, where you can select a city based on country and provence/state.
38 stars 15 forks source link

Transient bypasses WP localization function #126

Open mikezeb opened 1 year ago

mikezeb commented 1 year ago

It's impossible to translate states. The function acfcs_get_states() in acfcs-functions.php has the localization function buried in code that is bypassed by transient.

 $transient = get_transient( 'acfcs_states_' . strtolower( $country_code ) );
            if ( false == $transient || is_array( $transient ) && empty( $transient ) ) {
                $order = ' ORDER BY state_name ASC';
                if ( 'FR' == $country_code ) {
                    $order = " ORDER BY LENGTH(state_name), state_name";
                }

                global $wpdb;
                $table   = $wpdb->prefix . 'cities';
                $sql     = $wpdb->prepare( "SELECT * FROM $table WHERE country_code = %s GROUP BY state_code" . $order, strtoupper( $country_code ) );
                $results = $wpdb->get_results( $sql );

                $state_results = array();
                foreach ( $results as $data ) {
                    $state_results[ strtoupper( $country_code ) . '-' . $data->state_code ] = esc_attr__( $data->state_name, 'acf-city-selector' );
                }
Beee4life commented 1 year ago

Can't you just clear the transients so they're rebuilt ?

mikezeb commented 1 year ago

The only way that will work is if the site is just one language. It won't work on a multilingual site.

Beee4life commented 11 months ago

But it should generate a transient for each language code ? Is that not happening ?

Beee4life commented 7 months ago

I haven't visited this topic in a while... @mikezeb can you maybe clarify your issue a bit more ?