如何在php块中添加javascript变量作为参数?
我正在创建一个网站,它使用wordpress中的谷歌地图来显示多个标记,点击每个标记,就可以从数据库中检索相应的帖子。我正在尝试向标记添加一个侦听器,并希望它获得一个具有特定post id的自定义字段。我可以通过以下代码实现这一点,不使用post id的任何变量:如何在php块中添加javascript变量作为参数?,javascript,php,wordpress,google-maps,Javascript,Php,Wordpress,Google Maps,我正在创建一个网站,它使用wordpress中的谷歌地图来显示多个标记,点击每个标记,就可以从数据库中检索相应的帖子。我正在尝试向标记添加一个侦听器,并希望它获得一个具有特定post id的自定义字段。我可以通过以下代码实现这一点,不使用post id的任何变量: for (i=0;i<map.markers.length;i++){ thepostid = map.markers[i].postID; marker.addListener('click',
for (i=0;i<map.markers.length;i++){
thepostid = map.markers[i].postID;
marker.addListener('click', function() {
$('#article-bottom p').text('<?php echo get_field('sound_description', 59);
});
}
用于(i=0;iIt看起来您没有在第一个代码块中关闭php块,在第二个示例中关闭它两次您必须使用AJAX。没有其他方法了。@SergeyVidusov Sergey,因为我对这个AJAX概念还不熟悉,您能给我一个提示,说明如何在我的示例中实现它吗?提前感谢您的帮助。
$('#article-bottom p').text('<?php echo get_field('sound_description',?>' + thepostid + '<?php );?>');