WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Having an issue with 1 category, other 9 are fine

[Resolved] Having an issue with 1 category, other 9 are fine

  • 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

Viewing 1 replies (of 1 total)
  • 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 -->

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Having an issue with 1 category, other 9 are fine’ is closed to new replies.
Skip to toolbar