?
Solved

Custom Search and Results Page - Wordpress

Posted on 2014-11-06
4
Medium Priority
?
493 Views
Last Modified: 2014-12-21
So i have a custom wordpress form in my sidebar...

<form role="search" method="get" id="searchform" action="/updates/retail-part-time-jobs/search-jobs/">
    <div>
        <label class="screen-reader-text" for="s">Search for:</label>
        <input type="text" value="" name="s" id="s" />
        <input type="submit" id="searchsubmit" value="Search" />
    </div>
</form>

Open in new window


Now that Search results page template code is this:

<?php
/*
Template Name: Search Retail and Part Time
*/
global $query_string;

$query_args = explode("&", $query_string);
$search_query = array();

foreach($query_args as $key => $string) {
	$query_split = explode("=", $string);
	$search_query[$query_split[0]] = urldecode($query_split[1]);
} // foreach

$search = new WP_Query($search_query);

get_header(); ?>
	<?php if (!is_page(56)) { ?>
    <div class="subscribehead">
    	<a href="/updates/subscribe-to-updates/" title="subscribe to jobs">Receive Job Postings via Email</a>
    </div>
    <?php } ?>
	<div id="primary" class="content-area">
		<div id="content" class="site-content" role="main">

			

			<?php if ( have_posts() ) : ?>

			<header class="page-header">
				<h1 class="page-title"><?php printf( __( 'Search: %s', 'twentyfourteen' ), get_search_query() ); ?></h1>
			</header><!-- .page-header -->

				<?php
					// Start the Loop.
					while ( have_posts() ) : the_post();

						/*
						 * Include the post format-specific template for the content. If you want to
						 * use this in a child theme, then include a file called called content-___.php
						 * (where ___ is the post format) and that will be used instead.
						 */
						echo the_title(); 

					endwhile;
					// Previous/next post navigation.
					twentyfourteen_paging_nav();

				else :
					// If no content, include the "No posts found" template.
					?> none <?

				endif;
			?>


		</div><!-- #content -->
	</div><!-- #primary -->
    <?php get_sidebar( 'retail' ); ?>
<?php
get_footer();

Open in new window


I thought i followed http://codex.wordpress.org/Creating_a_Search_Page correctly

How ever if i goto /updates/retail-part-time-jobs/search-jobs/ just the page it shows up fine. (no results obviously)

but if using the form it goes to: "/updates/retail-part-time-jobs/search-jobs/?s=examplesearch"  which then returns 404 not found page.

Any help?
0
Comment
Question by:jporter80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Dzynit
ID: 40426855
You'll need to try changing the letter "s" in your search form code because that letter is reserved for the default wordpress search which will only work on the main domain url alone - no page names can be added to the url.
0
 

Author Comment

by:jporter80
ID: 40428333
okay, i can change the "s" but how does the page template gather that variable for the query
0
 
LVL 14

Accepted Solution

by:
Dzynit earned 2000 total points
ID: 40428706
You can see in the template code that it's splitting the query string by the = sign. So it shouldn't matter what variable you use for the search text box.
0
 

Author Comment

by:jporter80
ID: 40430278
okay that worked to get rid of the 404 ... but there is no results showing... any help with that?
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog, I will share you some basic tips for content marketing and to rank your website on Google.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question