Solved

Custom Search and Results Page - Wordpress

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Word files to Wordpress Posts 2 26
Img not displaying 11 16
PHP loop not working 4 32
SQL inner join confusion 15 21
Nowadays, it is so easy to get started with a website and all thanks to the Content Management Systems (CMS) like WordPress, Drupal, Joomla, and many others like them. However, if we talk about the reliability and ratings, WordPress definitely rules…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. 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 : Go t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 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

20 Experts available now in Live!

Get 1:1 Help Now