• I’m trying to get separate my search results by specific categories. So for instance if I were to type “search item”. I would receive a results page like the following.

    5 results for “search item”

    Videos (2)
    – Result 1
    – Result 2

    Images (3)
    – Result 1
    – Result 2

    I’m using the following code to attempt to achieve this

    <h1>Search: <?php echo $wp_query->found_posts; ?> results for "<?php echo wp_specialchars($s); ?>"</h1>
    
    <?php query_posts($query_string.'&cat='.$theme_motionstok_cat); if (have_posts()) : ?>
    	<?php include('search-content.php'); ?>
    <?php endif; wp_reset_query(); ?>
    
    <div class="clear"></div>
    
    <?php query_posts($query_string.'&cat='.$theme_photostok_cat); if (have_posts()) : ?>
    	<?php include('search-content.php'); ?>
    <?php endif; wp_reset_query(); ?>
    
    <div class="clear"></div>

    The problem is the category variable in query_posts seems to be ignored and every loop returns the same search results. Any help would be appreciated.

Viewing 2 replies - 16 through 17 (of 17 total)
  • Sorry, my “solution” is not right

    Now the correct version of search.php
    I have two categories to display in Search Results

    <?php
    get_header(); ?>
    <div class="content">
    			<?php
    				$s = get_search_query();
    			?>
    	<div class="search">
    		<div class="categoryThumbs">
    		<?php if (have_posts()) : ?>
    			<h3><?php printf( __( 'Search Results for: %s'), '<span>' . get_search_query() . '</span>' ); ?></h3>
    		<?php endif;?>
    			<?php query_posts("s='$s'&category_name=blog"); ?>
    				<?php if (have_posts()) : ?>
    					<?php $blogResults=0; ?>
    				<?php while (have_posts()) : the_post(); ?>
    					<?php
    						$blogResults++;
    					?>
    				<?php endwhile; ?>
    					<h4><?php echo $blogResults; ?> Results in BLOG</h4>
    					<?php while (have_posts()) : the_post(); ?>
    					<div class="films">
    						<div class="thumb">
    							<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
    						</div>
    						<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    						<div class="entry">
    							<?php the_excerpt() ?>
    						</div>
    					</div>
    					<?php endwhile; ?>
    				<?php endif;?>
    				<?php query_posts("s='$s'&category_name=films"); ?>
    				<?php if (have_posts()) : ?>
    					<?php $blogResults=0; ?>
    				<?php while (have_posts()) : the_post(); ?>
    					<?php
    						$blogResults++;
    					?>
    				<?php endwhile; ?>
    					<h4><?php echo $blogResults; ?> Results in Films</h4>
    					<?php while (have_posts()) : the_post(); ?>
    					<div class="films">
    						<div class="thumb">
    							<a href="<?php the_permalink() ?>"><?php the_post_thumbnail(); ?></a>
    						</div>
    						<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    						<div class="entry">
    							<?php the_excerpt() ?>
    						</div>
    					</div>
    					<?php endwhile; ?>
    				<?php endif;?>
    		<div class="spacer"></div>
    		</div>
    	</div>
    </div>
    <?php get_footer(); ?>

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Separate search results by category’ is closed to new replies.