Heim > Fragen und Antworten > Hauptteil
P粉3598508272023-08-17 00:34:02
要在关联数组中设置所需的数据,请尝试以下(已注释):
$featured_posts = get_field('parts', $postId->ID); if( $featured_posts ): // 在foreach循环之前始终初始化数组变量 $part_pages = array(); foreach( $featured_posts as $post ): setup_postdata($post); $permalink = get_permalink( $post->ID ); $title = get_the_title( $post->ID ); // 将链接设置为键,标题设置为值 $part_pages[$permalink] = $title; endforeach; wp_reset_postdata(); // 测试输出 echo '<pre>' . print_r($part_pages, true) . '</pre>'; endif;
注意:$part
变量未定义。