Solved

Custom Search and Results Page - Wordpress

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
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.
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 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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now