You’re calling wp_reset_postdata()
and closing the loop before displaying the content of the posts.
The WordPress Codex has a good example of how to build a custom query:
<?php
// example args
$args = array( 'posts_per_page' => 3 );
// the query
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- start of the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php endwhile; ?><!-- end of the loop -->
<!-- put pagination functions here -->
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
I’ve fixed the code for you here and added some comments:
<?php get_header(); ?>
<div id="section1-inner">
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
<div class="left-sec1">
<img src="https://wordpress.stackexchange.com/questions/248557/<?php bloginfo("template_directory'); ?>/images/logo.jpg" alt="">
</div>
<div class="left-sec2"><h2>Category</h2></div>
<div class="left-sec3">
<ul><?php if ( !dynamic_sidebar('Product Category') ) ?></ul>
</div>
<div class="left-sec4">
<ul><?php if ( !dynamic_sidebar('Homepage Banner') ) ?></ul>
</div>
</div>
<div class="col-lg-9 col-md-9 col-sm-12 col-xs-12">
<div class="form-gap"><?php get_search_form(); ?></div>
<div class="gallery"><?php wd_slider(1); ?></div>
<div class="clearfix"></div>
<h3 class="title"><?php printf( __( '%s', '' ), '<span>' . single_cat_title( '', false ) . '</span>' ); ?></h3>
<?php
$query = new WP_Query( array( 'post_type' => 'product', 'orderby' => 'menu_order', 'order' => 'ASC', 'showposts' => 5) );
if ($query->have_posts()) : // Always check if there are any results before looping
while ( $query->have_posts() ) {
$query->the_post(); ?>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="pbox">
<center><?php the_post_thumbnail(); ?></center>
<h3><a href="<?php the_permalink(); ?>"><?php the_title( ); ?></a><br></h3>
<h4><?php the_field('offer_price', $taxonomy); ?></h4>
<h5><?php the_field('price', $taxonomy); ?></h5>
<p class="text-center"><a href="<?php the_permalink(); ?>"><img src="https://wordpress.stackexchange.com/questions/248557/<?php bloginfo("template_directory'); ?>/images/download.png" alt=""></a></p>
</div>
</div>
<?php }
wp_reset_postdata(); // Called after the while loop for the query finishes
endif; ?>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
Edit: After reading your comments, it seems like what you want to achieve is showing only the posts for the current category. You’ve taken a different approach to this by setting up your own WP Query, so you’ll need to add another argument to get the posts for the currently queried category, using $wp_query->get_queried_object_id()
.
Replace your $query = ...
-line with the following:
$query = new WP_Query( array( 'post_type' => 'product', 'orderby' => 'menu_order', 'order' => 'ASC', 'showposts' => 5, 'cat' => $wp_query->get_queried_object_id()) );