Solved

Custom Search and Results Page - Wordpress

Posted on 2014-11-06
4
429 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

738 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