admin管理员组

文章数量:1130349

I have used wp_localize_script() to pass a variable to a javascript file.

var countries = [searchresults.data];

The variable is getting passed but I want it in a js file like below:

var countries = [item1,item2,item3];

The variable is correct searchresults.data = item1,item2,item3, but the countries variable has to be like var countries = [item1,item2,item3]; iIam not able to do. Please help


This is the $data that I passed

 $data = array(
      'data' => $searchresult,
    );
 wp_localize_script( 'searchautocompleter', 'searchresults', $data );

I have used wp_localize_script() to pass a variable to a javascript file.

var countries = [searchresults.data];

The variable is getting passed but I want it in a js file like below:

var countries = [item1,item2,item3];

The variable is correct searchresults.data = item1,item2,item3, but the countries variable has to be like var countries = [item1,item2,item3]; iIam not able to do. Please help


This is the $data that I passed

 $data = array(
      'data' => $searchresult,
    );
 wp_localize_script( 'searchautocompleter', 'searchresults', $data );

本文标签: theme developmentHow to echo inside the js file with wplocalizescript