Пользовательский запрос, показывающий только одну запись на странице - PullRequest
0 голосов
/ 04 июня 2018

Я пытаюсь создать карту с маркерами.Код работает иначе, но он отображает только один результат из каждого поста.

<?php 
    $the_query_map = new WP_Query( array( 'post_type' => 'country', 'posts_per_page' => -1 ) );

    if($the_query_map->have_posts()) :
    while($the_query_map->have_posts()): $the_query_map->the_post();

    $the_ID = get_the_ID();

    if( have_rows('single_dealer') ):
    while ( have_rows('single_dealer') ) : the_row();

    $get_google_map = get_sub_field('map', $value);
    $marker_description = get_sub_field('description', $value);

    $output_map[$the_ID]['map'] = '<div class="marker" data-lat="'.$get_google_map['lat'].'" data-lng="'.$get_google_map['lng'].'">'.
    $marker_description.'</div>';

    endwhile; endif;
    wp_reset_postdata();
    endwhile; endif;


    ?><div class="acf-map"><?php
foreach( $output_map as $key => $map_marker ):
    echo $map_marker['map'];
    endforeach;
    ?>
</div>

Как я могу получить мой код для отображения всех результатов сообщения вместо одного?

1 Ответ

0 голосов
/ 04 июня 2018

Вы должны поставить конец цикла wp_reset_postdata();.

<?php 
    $the_query_map = new WP_Query( array( 'post_type' => 'country', 'posts_per_page' => -1 ) );

    if($the_query_map->have_posts()) :
    while($the_query_map->have_posts()): $the_query_map->the_post();

    $the_ID = get_the_ID();

    if( have_rows('single_dealer') ):
    while ( have_rows('single_dealer') ) : the_row();

    $get_google_map = get_sub_field('map', $value);
    $marker_description = get_sub_field('description', $value);

    $output_map[$the_ID]['map'] = '<div class="marker" data-lat="'.$get_google_map['lat'].'" data-lng="'.$get_google_map['lng'].'">'.
    $marker_description.'</div>';

    endwhile; endif;

    endwhile; 
 wp_reset_postdata();
endif;


    ?><div class="acf-map"><?php
foreach( $output_map as $key => $map_marker ):
    echo $map_marker['map'];
    endforeach;
    ?>
</div>
...