{"id":2582,"date":"2015-05-09T07:58:49","date_gmt":"2015-05-09T07:58:49","guid":{"rendered":"http:\/\/www.vishmax.com\/en\/?p=2582"},"modified":"2015-05-09T07:58:49","modified_gmt":"2015-05-09T07:58:49","slug":"how-to-create-a-search-page-in-wordpress","status":"publish","type":"post","link":"https:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/","title":{"rendered":"How to create a search page in wordpress"},"content":{"rendered":"<p>Creating a search page is an essential part of WordPress theme development. Here is a post which contains how to create a search.php page in a better way. Search.php is the page where the theme will show all search results, so displaying search results we need to create two things, first is a search form and other one is search page. Below is the code for search form and search.php template in WordPress.<\/p>\n<h2>create a search form in WordPress<\/h2>\n<p>There are multiple ways to create a search form in WordPress here is one method. Create a searchform.php file in your theme folder and place and save the following php code in it.<\/p>\n<pre lang=\"php\">\r\n\r\n\r\n<form role=\"search\" method=\"get\" id=\"searchform\" action=\"<?php echo home_url( '\/' ); ?>\">\r\n    <div><label class=\"screen-reader-text\" for=\"s\"><\/label>\r\n        <input type=\"text\" value=\"\" placeholder=\"Search...\" name=\"s\" id=\"s\" \/>\r\n        <input type=\"submit\" id=\"searchsubmit\" value=\"Search\" \/>\r\n    <\/div>\r\n<\/form>\r\n\r\n\r\n<\/pre>\n<p>You can include the form in any where by calling the file in following way.<\/p>\n<pre lang=\"php\">\r\n\r\n<?php get_search_form(); ?>\r\n\r\n<\/pre>\n<h2>create a WordPress search page for showing results<\/h2>\n<p>Below is a example of search.php, create a php file called search.php in your theme folder, then copy and paste below code to it.<\/p>\n<pre lang=\"php\">\r\n\r\n\r\n<?php\r\n\/*\r\nTemplate Name: Search Page\r\n*\/\r\n?>\r\n\r\n<?php get_header(); ?>\r\n\r\n\t<section id=\"top\" class=\"one\">\r\n\r\n\t\t<div class=\"container\">\r\n\r\n\t\t\t<div class=\"content\">\r\n\r\n\t<?php if (have_posts()) : ?>\r\n\r\n\t\t<h2 class=\"pagetitle\">Search Results for \"<?php echo $s ?>\"<\/h2>\r\n\r\n\t\t<div class=\"navigation\">\r\n\t\t\t<div class=\"alignleft\"><?php next_posts_link('&laquo; Previous') ?><\/div>\r\n\t\t\t<div class=\"alignright\"><?php previous_posts_link('Next &raquo;') ?><\/div>\r\n\t\t<\/div>\r\n\t\t\r\n\t\t<div class=\"clear\"><\/div>\r\n\r\n\t\t<?php while (have_posts()) : the_post(); ?>\r\n\r\n\t\t\t<div class=\"post\" id=\"post-<?php the_ID(); ?>\">\r\n\r\n\t\t\t\t<h1 class=\"large nomargin\"><a href=\"<?php the_permalink() ?>\" rel=\"bookmark\" title=\"Permanent Link to <?php the_title(); ?>\"><?php the_title(); ?><\/a><\/h1>\r\n\t\t\t\t<?php\r\n\t\t\t\t\/\/ Support for \"Search Excerpt\" plugin\r\n\t\t\t\t\/\/ http:\/\/fucoder.com\/code\/search-excerpt\/\r\n\t\t\t\tif ( function_exists('the_excerpt') &#038;&#038; is_search() ) {\r\n\t\t\t\t\tthe_excerpt();\r\n\t\t\t\t} ?>\r\n\t\t\t\t<p class=\"small\">\r\n\t\t\t\t\t<?php the_time('F jS, Y') ?> &nbsp;|&nbsp; \r\n\t\t\t\t\t<!-- by <?php the_author() ?> -->\r\n\t\t\t\t\tPublished in\r\n\t\t\t\t\t<?php the_category(', ');\r\n\t\t\t\t\t\tif($post->comment_count > 0) { \r\n\t\t\t\t\t\t\t\techo ' &nbsp;|&nbsp; ';\r\n\t\t\t\t\t\t\t\tcomments_popup_link('', '1 Comment', '% Comments'); \r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t?>\r\n\t\t\t\t<\/p>\r\n\t\t\t\t\r\n\t\t\t<\/div>\r\n\t\t\t\r\n\t\t\t<hr>\r\n\t\t<?php endwhile; ?>\r\n\r\n\t\t<div class=\"navigation\">\r\n\t\t\t<div class=\"alignleft\"><?php next_posts_link('&laquo; Previous') ?><\/div>\r\n\t\t\t<div class=\"alignright\"><?php previous_posts_link('Next &raquo;') ?><\/div>\r\n\t\t<\/div>\r\n\r\n\t<?php else : ?>\r\n\r\n\t\t<h2 class=\"center\">No posts found. Try a different search?<\/h2>\r\n\t\t<?php include (TEMPLATEPATH . '\/searchform.php'); ?>\r\n\r\n\t<?php endif; ?>\r\n\r\n\t\t<\/div> <!-- \/container -->\r\n\t<\/div> <!-- \/maincontent-->\r\n\r\n\t<?php get_sidebar(); ?>\r\n\r\n\t<\/section>\r\n\r\n<?php get_footer(); ?>\r\n\r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Creating a search page is an essential part of WordPress theme development. Here is a post which contains how to create a search.php page in a better way. Search.php is the page where the theme will show all search results, so displaying search results we need to create two things, first is a search form [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[44],"tags":[72,83],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.2.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to create a search page in wordpress - Vishmax.com<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create a search page in wordpress - Vishmax.com\" \/>\n<meta property=\"og:description\" content=\"Creating a search page is an essential part of WordPress theme development. Here is a post which contains how to create a search.php page in a better way. Search.php is the page where the theme will show all search results, so displaying search results we need to create two things, first is a search form [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/\" \/>\n<meta property=\"og:site_name\" content=\"Vishmax.com\" \/>\n<meta property=\"article:published_time\" content=\"2015-05-09T07:58:49+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/785fa94b56eb17ae7706d30777d6ab93\"},\"headline\":\"How to create a search page in wordpress\",\"datePublished\":\"2015-05-09T07:58:49+00:00\",\"dateModified\":\"2015-05-09T07:58:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/\"},\"wordCount\":173,\"publisher\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/#organization\"},\"keywords\":[\"Code Library\",\"WP Snippets\"],\"articleSection\":[\"Labs\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/\",\"url\":\"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/\",\"name\":\"How to create a search page in wordpress - Vishmax.com\",\"isPartOf\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/#website\"},\"datePublished\":\"2015-05-09T07:58:49+00:00\",\"dateModified\":\"2015-05-09T07:58:49+00:00\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.vishmax.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create a search page in wordpress\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#website\",\"url\":\"http:\/\/www.vishmax.com\/en\/\",\"name\":\"Vishmax.com\",\"description\":\"Software Company in Calicut for Web Design and eCommerce\",\"publisher\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.vishmax.com\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#organization\",\"name\":\"Vishmax.com\",\"url\":\"http:\/\/www.vishmax.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vishmax.com\/en\/wp-content\/uploads\/2023\/03\/logo-vishmax.png\",\"contentUrl\":\"https:\/\/www.vishmax.com\/en\/wp-content\/uploads\/2023\/03\/logo-vishmax.png\",\"width\":150,\"height\":50,\"caption\":\"Vishmax.com\"},\"image\":{\"@id\":\"http:\/\/www.vishmax.com\/en\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/785fa94b56eb17ae7706d30777d6ab93\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e218268870406c917d20b442936d9e68?s=96&d=monsterid&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e218268870406c917d20b442936d9e68?s=96&d=monsterid&r=g\",\"caption\":\"admin\"},\"url\":\"https:\/\/www.vishmax.com\/en\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to create a search page in wordpress - Vishmax.com","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/","og_locale":"en_US","og_type":"article","og_title":"How to create a search page in wordpress - Vishmax.com","og_description":"Creating a search page is an essential part of WordPress theme development. Here is a post which contains how to create a search.php page in a better way. Search.php is the page where the theme will show all search results, so displaying search results we need to create two things, first is a search form [&hellip;]","og_url":"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/","og_site_name":"Vishmax.com","article_published_time":"2015-05-09T07:58:49+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/#article","isPartOf":{"@id":"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/"},"author":{"name":"admin","@id":"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/785fa94b56eb17ae7706d30777d6ab93"},"headline":"How to create a search page in wordpress","datePublished":"2015-05-09T07:58:49+00:00","dateModified":"2015-05-09T07:58:49+00:00","mainEntityOfPage":{"@id":"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/"},"wordCount":173,"publisher":{"@id":"http:\/\/www.vishmax.com\/en\/#organization"},"keywords":["Code Library","WP Snippets"],"articleSection":["Labs"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/","url":"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/","name":"How to create a search page in wordpress - Vishmax.com","isPartOf":{"@id":"http:\/\/www.vishmax.com\/en\/#website"},"datePublished":"2015-05-09T07:58:49+00:00","dateModified":"2015-05-09T07:58:49+00:00","breadcrumb":{"@id":"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.vishmax.com\/en\/labs\/how-to-create-a-search-page-in-wordpress\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.vishmax.com\/en\/"},{"@type":"ListItem","position":2,"name":"How to create a search page in wordpress"}]},{"@type":"WebSite","@id":"http:\/\/www.vishmax.com\/en\/#website","url":"http:\/\/www.vishmax.com\/en\/","name":"Vishmax.com","description":"Software Company in Calicut for Web Design and eCommerce","publisher":{"@id":"http:\/\/www.vishmax.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.vishmax.com\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/www.vishmax.com\/en\/#organization","name":"Vishmax.com","url":"http:\/\/www.vishmax.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vishmax.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/www.vishmax.com\/en\/wp-content\/uploads\/2023\/03\/logo-vishmax.png","contentUrl":"https:\/\/www.vishmax.com\/en\/wp-content\/uploads\/2023\/03\/logo-vishmax.png","width":150,"height":50,"caption":"Vishmax.com"},"image":{"@id":"http:\/\/www.vishmax.com\/en\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/785fa94b56eb17ae7706d30777d6ab93","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vishmax.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e218268870406c917d20b442936d9e68?s=96&d=monsterid&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e218268870406c917d20b442936d9e68?s=96&d=monsterid&r=g","caption":"admin"},"url":"https:\/\/www.vishmax.com\/en\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/posts\/2582"}],"collection":[{"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/comments?post=2582"}],"version-history":[{"count":0,"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/posts\/2582\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/media?parent=2582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/categories?post=2582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vishmax.com\/en\/wp-json\/wp\/v2\/tags?post=2582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}