0

So I created a custom category.php where I have the following loop:

<div id="category__product-grid" class="row">
<?php

// The Loop
while ( have_posts() ) : the_post(); ?>

<div class="col-md-4 col-product-item">
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><div class="cat__featured-img"><?php the_post_thumbnail(); ?></div></a>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
</div>

<?php endwhile; 

else: ?>
<p>Sorry, no posts matched your criteria.</p>
</div>  

I broke my head trying to understand how can I exclude the needed categories from this loop and the required posts as well. Would appreciate any help!

2
  • did you try pre_get_posts?
    – rudtek
    Dec 8, 2018 at 16:16
  • @rudtek no, could you, please, let me know more details?
    – Jamdev
    Dec 8, 2018 at 16:25

1 Answer 1

0

Here is a correct way:

<div id="category__product-grid" class="row">
<?php query_posts( array( 'cat' => array(6,-45), 'post__not_in' => array(-598), 'orderby' => 'title', 'order' => 'ASC' ) ); ?>

<?php

// The Loop
while ( have_posts() ) : the_post(); ?>

<div class="col-md-4 col-product-item">
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><div class="cat__featured-img"><?php the_post_thumbnail(); ?></div></a>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
</div>

<?php endwhile; 

else: ?>
<p>Sorry, no posts matched your criteria.</p>
</div>  

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.