Php jquery数组中的acf字段

Php jquery数组中的acf字段,php,jquery,wordpress,foreach,Php,Jquery,Wordpress,Foreach,我创建acf字段以上载徽标图像 我需要获取所有url徽标,并将它们放入jQuery数组中,如下所示: var logos = ["http://www.mylogo.com/img1.jpg", "http://www.mylogo.com/img2.jpg", "http://www.mylogo.com/img3.jpg"]; 我的ACF字段: $wall_references = get_field('wall_references'); 我写道: <script typ

我创建acf字段以上载徽标图像

我需要获取所有url徽标,并将它们放入jQuery数组中,如下所示:

var logos = ["http://www.mylogo.com/img1.jpg", "http://www.mylogo.com/img2.jpg", "http://www.mylogo.com/img3.jpg"];
我的ACF字段:

    $wall_references = get_field('wall_references');
我写道:

<script type="text/javascript" language="javascript">
var logos = new Array();
<?php foreach($wall_references as $wall_reference){ ?>
    logos.push('<?php echo $wall_reference['ref_logo']['url']; ?>');
<?php } ?>
</script>

我在这里看到一个小的引号错误,用双引号代替单引号

logos.push("<?php echo $wall_reference['ref_logo']['url']; ?>");

到底有什么困难


如果你在console.log上记录logos数组,你就拥有了你想要的东西

我不想在控制台日志中打印我的数组,而是直接在我的文档中。我只是在控制台日志中打印到以快速测试它。它正在打印到您的文档中。在本例中,.push将作为参数传递的内容添加到数组中。因此,您的徽标数组正是您在问题中所描述的。你需要在它上面循环,然后你可以对元素做任何你想做的事情。另外,请注意@Rishi的答案-修复引号!我希望数组直接在我的页面中,而不是在我的控制台中。因为我需要在document.ready中使用带有jQueryRap的数组,它将执行,您可以在jquery中准备好它。但老实说,我很有信心你甚至不需要这样做-它应该已经是可用的-只是尝试一下!
var logos = ["http://www.mylogo.com/img1.jpg", "http://www.mylogo.com/img2.jpg", "http://www.mylogo.com/img3.jpg"];
logos.push("<?php echo $wall_reference['ref_logo']['url']; ?>");