acf-city-selector icon indicating copy to clipboard operation
acf-city-selector copied to clipboard

Transient bypasses WP localization function

Open mikezeb opened this issue 1 year ago • 4 comments

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' );
                }

mikezeb avatar Jul 28 '23 02:07 mikezeb

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

Beee4life avatar Jul 28 '23 14:07 Beee4life

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

mikezeb avatar Jul 28 '23 15:07 mikezeb

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

Beee4life avatar Oct 22 '23 22:10 Beee4life

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

Beee4life avatar Mar 09 '24 15:03 Beee4life