In my index page there are two slider one is working fine but the second one is giving some problems.
<?php
global $post;
$i=0;
$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');
$i++;
?>
<!-- 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></h2>
<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>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
endforeach;
?>
<?php
global $small_post;
$x=0;
$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');
$x++;
?>
<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>
</div>
</div>
<?php
endforeach;
?>
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.
In my index page there are two slider one is working fine but the second one is giving some problems.
<?php
global $post;
$i=0;
$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');
$i++;
?>
<!-- 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></h2>
<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>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
endforeach;
?>
<?php
global $small_post;
$x=0;
$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');
$x++;
?>
<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>
</div>
</div>
<?php
endforeach;
?>
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.
As you are using two loops in a page, that's why you need to reset your query.
Get more details from here https://digwp/2011/09/3-ways-to-reset-the-wordpress-loop/
I Uses this and this worked.
and in the last i added
Now, again i used in the 2nd slider and works like charm, Thanks Mohammad Tajul Islam for the great suggestion.