Pass multiple PHP variables to JS in Options Page

I’m passing variables from options to the front-end using wp_localize_script. Issue is that now I have 71 input fields in the options page with these ids: calc_m_transport_1, calc_m_transport_2 and so on till 71.

What would be the efficient way to pass this data to the front-end?

Right now this is how I’m doing it:

$phpValues = array(
        'value1' => get_option( 'plugin_name_value1'),
        );
        wp_localize_script( $this->plugin_name, 'phpValues', $phpValues )

1 Answer
1

I think you are looking like :

$phpValues = array();
for($i=1;$i<=71;$i++){
    $phpValues['value'.$i] = get_option('plugin_name_value'.$i);
}

wp_localize_script( $this->plugin_name, 'phpValues', $phpValues )

Leave a Comment