In my index page there are two slider one is working fine but the second one is giving some problems.


global $post;
$args = array('post_per_page' => -1, 'post_type' => 'slider-items', 'page' => $paged, 'order' => 'ASC');
$myposts = get_posts($args);

foreach( $myposts as $post ) : setup_postdata($post);

    $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'slider-items');


                <!-- Slider Item -->
                <div class="owl-item main_slider_item">

                    <div class="main_slider_item_bg" style="background-image:url(<?php echo $large_image_url[0]; ?>)"></div>
                    <div class="main_slider_shapes"><img src="<?php echo get_template_directory_uri() ?>/images/main_slider_shapes.png" alt="" style="width: 100% !important;"></div>
                    <div class="container">
                        <div class="row">
                            <div class="col slider_content_col">
                                <div class="main_slider_content">
                                    <h2><?php the_content(); ?></h2>
                                    <div class="button discover_button">
                                        <a href="#" class="d-flex flex-row align-items-center justify-content-center">discover<img src="<?php echo get_template_directory_uri() ?>/images/arrow_right.svg" alt=""></a>





global $small_post;
$small_args = array('post_per_page' => -1, 'post_type' => 'bottom-slider-items', 'page' => $small_paged);
$small_myposts = get_posts($small_args);

foreach( $small_myposts as $small_post ) : setup_postdata($small_post);

    $small_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($small_post->ID), 'bottom-slider-items');


                            <div class="owl-item testimonials_item d-flex flex-column align-items-center justify-content-center text-center">
                                <div class="testimonials_content">
                                    <div class="test_user_pic" style="background-image:url(<?php echo $small_image_url[0]; ?>)"></div>
                                    <div class="test_name"><?php echo get_the_title(); ?></div>
                                    <div class="test_title">Company CEO</div>
                                    <div class="test_quote">"</div>
                                    <p><?php the_content(); ?></p>


When I call get_the_title() it shows me the title of first loop. I have added three sliders post in the first one and the second loop showing title of the last one. Please help.

2 Answers 2


As you are using two loops in a page, that's why you need to reset your query.

  1. wp_reset_postdata() -> best used after custom or multiple loops created with WP_Query
  2. wp_reset_query() -> best used after a query_posts loop to reset a custom query
  3. rewind_posts() -> best for re-using the same query on the same page

Get more details from here https://digwp.com/2011/09/3-ways-to-reset-the-wordpress-loop/


I Uses this and this worked. enter image description here

and in the last i added enter image description here

Now, again i used in the 2nd slider and works like charm, Thanks Mohammad Tajul Islam for the great suggestion.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.