您正在覆盖$post_ids
每个上的变量while
循环,从不收集它们。
可以使用
$post_ids = array();
while (have_posts()) : the_post();
$post_ids[] = get_the_ID();
endwhile;
var_dump($post_ids); // this is an array of ids
然而,有一种更简单的方法,您可以跳过whle循环,只需运行:
if( function_exists( \'wpseo_local_show_map\' ) && have_posts() ) {
// this is an array of ids
$post_ids = wp_list_pluck( $GLOBALS[\'wp_query\']->posts, \'ID\' );
$params = array(
\'id\' => $post_ids,
\'echo\' => true,
\'width\' => 425,
\'height\' => 350,
\'zoom\' => 10,
\'show_route\' => true
);
wpseo_local_show_map( $params );
}