Title: Creating custom search.php
Last modified: August 30, 2016

---

# Creating custom search.php

 *  [EnergyFreak](https://wordpress.org/support/users/energyfreak/)
 * (@energyfreak)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/creating-custom-searchphp/)
 * Hi,
 * I’ve been searching the web and codex for hours and can’t find anyone that has
   done this before.
 * I want to create my own search.php. Essentially, I want my search.php to be like
   my category.php. So if it returns a post or many posts it will show them just
   like if it was posts in a category.
 * I’ve separated searchform.php and search.php. This is my search.php:
 *     ```
       <?php
       /*
        *
        * main theme
        *
       */
   
       get_header(); ?>
   
       <body>
   
          	<?php get_template_part( 'navigation' ); ?> 
   
       	<!-- Main -->
       	<section id="main" class="category-page">
       		<div class="container">
       			<div class="row">
       				<div class="col-md-8">
       					<div class="post-wrap">
   
                           	<?php if ( have_posts() ) : ?>
   
                               <h2><?php printf( __( 'Search Results for: %s', 'maintheme' ), get_search_query() ); ?></h2>
   
       						<?php while ( have_posts() ) : the_post(); ?>
   
                               <?php
       				/*
       				 * Run the loop for the search to output the results.
       				 * If you want to overload this in a child theme then include a file
       				 * called content-search.php and that will be used instead.
       				 */
       				get_template_part( 'category' );
   
       			// End the loop.
       			endwhile;
   
       			// Previous/next page navigation.
       			the_posts_pagination( array(
       				'prev_text'          => __( 'Previous page', 'twentyfifteen' ),
       				'next_text'          => __( 'Next page', 'twentyfifteen' ),
       				'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyfifteen' ) . ' </span>',
       			) );
   
       		// If no content, include the "No posts found" template.
       		else :
       			get_template_part( 'content', 'none' );
   
       		endif;
       		?>
   
       					</div><!-- /.social-media-posts -->
       				</div><!-- /.col-md-8 -->
       				<div class="col-md-4">
   
       					<?php get_sidebar(); ?> 
   
       				</div><!-- /.col-md-4 -->
       			</div><!-- /.row -->
       		</div><!-- /.container -->
       	</section>
   
       	<?php get_footer(); ?>
       ```
   
 * This is my searchform.php:
 *     ```
       <form action="<?php bloginfo('url'); ?>/" id="searchform" class="search-form" method="get" role="search">
       <input type="text" id="s" placeholder="Search" class="search-field">
       <input type="submit" value="" id="searchsubmit" class="search-submit">
       <a class="search-close" href="#"><i class="fa fa-times-circle"></i></a>
       </form>
       ```
   
 * When I enter something in my search box, nothing happens, it just refreshes the
   page… Do I need to add something in functions.php or…? By the way, this is a 
   complete custom theme, I am converting static HTML files to a wordpress theme
   so I did not code all the default wordpress PHP pages yet. Could be the reason?
 * Thanks for any help!

The topic ‘Creating custom search.php’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [EnergyFreak](https://wordpress.org/support/users/energyfreak/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/creating-custom-searchphp/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
