0

My While loop is breaking the rest of my PHP on the site. I am using Advanced Custom Fields also as a reference. Below I put my code that is working but again breaking the rest of the site (and or anything below this).

Any Suggestions Thank You For the Help I have stuck for to long!

<?php 
    $query = array( 'post_type' => 'slides', 'orderby' => 'ASC' );
    $loop = new WP_Query($query);
    while ( $loop->have_posts() ) : $loop->the_post();

        $title = get_the_title();
        $image_object = get_field('slides');
        $alt = $image_object['title'];
        $sizes = $image_object['sizes'];
        $image = $sizes['slider'];

        echo '<div>';
        echo '<div class="slide">';
        echo '<img src="' . $image . '" alt="' . $alt . '" />';
        echo '</div>';
        echo '</div>';
    endwhile;
?>  

1 Answer 1

3

Try to add wp_reset_query() after your custom loop:

<?php 
    $query = array( 'post_type' => 'slides', 'orderby' => 'ASC' );
    $loop = new WP_Query($query);
    while ( $loop->have_posts() ) : $loop->the_post();

        $title = get_the_title();
        $image_object = get_field('slides');
        $alt = $image_object['title'];
        $sizes = $image_object['sizes'];
        $image = $sizes['slider'];

        echo '<div>';
        echo '<div class="slide">';
        echo '<img src="' . $image . '" alt="' . $alt . '" />';
        echo '</div>';
        echo '</div>';
    endwhile;
    wp_reset_query();
?>  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.