Solved

Custom Search and Results Page - Wordpress

Posted on 2014-11-06
4
425 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
  • 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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to dynamically set the form action using jQuery.

680 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