使用offset
参数,仅获取1个结果:
global $my_page_offset;
if(!isset($my_page_offset))
$my_page_offset = 0;
$pages = get_pages(array(
\'child_of\' => $post->ID,
\'sort_column\' => \'menu_order\',
\'offset\' => $my_page_offset,
\'number\' => 1,
));
$my_page_offset++;
...
我在这里假设您对这些循环没有太多的控制,因为您要多次执行它们。这就是为什么全局变量。。。
<小时>Last try:
之后var infowindow;
添加以下内容:
<?php
$pages = get_pages(array(\'child_of\' => $post->ID, \'sort_column\' => \'menu_order\'));
$data = array();
foreach($pages as $post){
setup_postdata($post);
$fields = get_fields();
$data[] = \'<p>\'.$fields->company_name.\'</p>\';
}
wp_reset_query();
// the js array
echo \'var marker_data = ["\'.implode(\'","\', $data).\'"];\';
?>
现在是信息窗口。设置内容应为:
infowindow.setContent(marker_data[i]);