WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Having an issue with 1 category, other 9 are fine (2 posts)

  1. alexgraham
    Member
    Posted 4 years ago #

    Hi Folks,
    Working on my third wp theme for a customer and having some very strange behaviour when trying to display the contents of one category in particular (other 9 are working fine).

    Category details:
    name: £1000 and over
    slug: plus-1000

    category.php custom loop:

    <div id="container">
    		<div id="content">
    			<?php $cat = single_cat_title("", false); ?>
    			<div id="latest-products">
    				<h2><?php echo $cat; ?></h2>
    				<div class="product-container">
    				<?php
    				$temp = $wp_query;
    				$wp_query= null;
    				$wp_query = new WP_Query();
    				$wp_query->query('showposts=20'.'&paged='.$paged.'&category_name='.$cat);
    				while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    					<div class="product">
    						<!-- displays product stuff -->
    					</div><!-- .product -->
    				<?php endwhile;	?>
    
    				<!-- Paging stuff -->
    				</div>
    			</div>
    
    		</div><!-- #content .hfeed -->
    	</div><!-- #container -->

    For this one category I'm getting no products, despite there being 18 associated. I've double checked the links and it's definitely going to the right page. Is there any issues when using 'and'/'or' in a category name when passing it to $wp_query ?
    Any help appreciated,
    Alex

  2. alexgraham
    Member
    Posted 4 years ago #

    fixed with:

    <div id="container">
    		<div id="content">
    			<?php
    				$cat = single_cat_title("", false);
    				$cat_id = get_cat_ID($cat)
    			?>
    			<div id="latest-products">
    				<h2><?php echo $cat; ?></h2>
    				<div class="product-container">
    				<?php
    				$temp = $wp_query;
    				$wp_query= null;
    				$wp_query = new WP_Query();
    				$wp_query->query('showposts=20'.'&paged='.$paged.'&cat='.$cat_id);
    				while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    					<div class="product">
    						<!-- displays product stuff -->
    					</div><!-- .product -->
    				<?php endwhile;	?>
    
    				<!-- Paging stuff -->
    				</div>
    			</div>
    
    		</div><!-- #content .hfeed -->
    	</div><!-- #container -->

Topic Closed

This topic has been closed to new replies.

About this Topic